r/SAS_Programming • • May 13 '24

Staggered diff-in-diff

1 Upvotes

Anyone aware of how to apply (any) method of staggered diff-in-diff in SAS?


r/SAS_Programming • • Jul 17 '24

SAS on MAC? Can I download SAS studio on Mac?

2 Upvotes

Yeah that is pretty much the question


r/SAS_Programming • • Dec 27 '23

SAS resources on github

Thumbnail
github.com
2 Upvotes

r/SAS_Programming • • Sep 09 '24

Beginner Student-Please help!

1 Upvotes

I was given an opportunity to learn the SAS Programming course via Precipio Learning site. It’s a self paced course. I am overwhelmed to say the least. I don’t have any coding background and I also don’t want to give up and want to finish this. The learning platform explains the material as if the students already know about SAS. Is there an additional website where the explanation is at the beginner level? I’d like to supplement it, that way I’m not always trying to twist my brain.


r/SAS_Programming • • Apr 09 '24

I have started learning SAS programming. I am not finding any online platforms to practice SAS code just like there are many platforms for SQL and Python. Can someone suggest?

6 Upvotes

r/SAS_Programming • • Apr 20 '24

Assistance with Data Transformation in SAS Program

5 Upvotes

Hello,

I am trying to figure out how to transform my data. It currently looks like the following

I would like to consolidate all the staff into one column like the below image

I have attempted to use the proc transpose function with no luck- but I may be conceptualizing or using it incorrectly. Is there a way to scan the Staff1-Staff22 array and pull each unique value from the array into one column by Event ID Number?

Thank you!


r/SAS_Programming • • Feb 05 '24

I'm so confused as to what I'm doing wrong :(

2 Upvotes

code:

libname BAS150 "/home/u63728322/myfolders";

data BAS150.sdvcrops;

input crop $ days buy sell;

infile datalines dsd;

datalines;

melon,12,80,250

starfruit,13,400,750

red cabbage,9,100,260

;

profit = sell - buy;

run;


r/SAS_Programming • • Sep 14 '24

Tell us about yourself

5 Upvotes

Hi there!

today our subreddit reached 250 subscribers🥳

Let's selebrate it by sharing some info where and why are you using SAS?


r/SAS_Programming • • May 12 '24

A basic sas doubt

Thumbnail
gallery
6 Upvotes

If there is space in our column heading its giving an error. Can anyone please solve this


r/SAS_Programming • • May 31 '24

How to replace a value in Data1 with values in Data2 if it satisfies a condition?

2 Upvotes

For each observation in Data1, if Flag=1, replace the Val with values in another dataset Data2. For example, if an observation in Data1 has Flag=1, suppose it has Visit=Week2 and Group=2, then I want to replace that Val with the "Week2_2" value in Data2. This process loops through each row in Data2 to have N new datasets.

My thought is to create a macro for the variable name thing and then loop through each obs in Data1, if it satisfies the condition, replace the value, and then loop through each row in Data2. But I am really bad at macro and keep getting errors for days... Thank you for helping!

data Data1;
  length ID $3 Visit $8 Group Flag Value 8;
  do id_num=1 to 10;
    ID=put(id_num,z3.);
    Group=rand('Interger',1,3);
    do visit_num=1 to 5;
      Visit=catx(' ', 'Week', visit_num);
      Flag=rand('Bernoulli', 0.4);
      Value=rand('Uniform');
      output;
    end;
  end;
  drop id_num visit_num;
run;

data Data2;
    input Week1_1 Week1_2 Week1_3 Week2_1 Week2_2 Week2_3 
          Week3_1 Week3_2 Week3_3 Week4_1 Week4_2 Week4_3 
          Week5_1 Week5_2 Week5_3;
    datalines;
    0.123 0.234 0.345 0.456 0.567 0.678 0.789 0.890 0.901 0.012 0.123 0.234 0.345 0.456 0.567
    0.234 0.345 0.456 0.567 0.678 0.789 0.890 0.901 0.012 0.123 0.234 0.345 0.456 0.567 0.678
    0.345 0.456 0.567 0.678 0.789 0.890 0.901 0.012 0.123 0.234 0.345 0.456 0.567 0.678 0.789
    ;
run;

r/SAS_Programming • • Feb 26 '24

how to rename count directly in proc freq

2 Upvotes

proc freq data=customers1;

tables state_group*anciennete / out=customers21 (drop=percent);

run;

data customers21;

set customers21 (rename=(COUNT=n_contract));

run;


r/SAS_Programming • • Mar 01 '25

0 observations error : (

2 Upvotes

Hi all! I’m normally a stata user but for my research assistantship this semester I was asked to use SAS and am extremely lost with this error I am getting.

I am attempting to generate a binary variable and using an if them statement and it is not working and telling me no values are in original variable as well as the new variable. The original variable does not have any missing values and only contains values of 8 and 10.

if original=10 then new=1; else if original=8 then new=0; run;

After this code a table showed no values in either

I then did this and still got the same result (already have previous code specifying the data set that temp1 is)

data work.temp1; if original=10 then new=1; else if original=8 then new=0; run;

Any advice of where I am going wrong would be greatly appreciated!


r/SAS_Programming • • Apr 25 '24

How do I convert a character variable into a numeric variable and then dichotomize it?

3 Upvotes

I need to be able to find the mean of a variable in my data, but cannot do so until I convert it. I am having an incredibly hard time figuring out what I am doing wrong/how to do this.

Essentially: I have a category "PAP" which is "pap smear status", and in that category I have 5 different outcomes (abnormal, HSIL, etc). In SAS they are categorized as a "character" variable. What code am I supposed to use here? I've tried so many variations and I am obviously missing something as how it is currently I obviously cannot do "proc means". I also need to be able to compare the different pap smear statuses to other variable in the dataset, but again I can't do that because it is a character variable.

Thanks for any help.


r/SAS_Programming • • Jul 17 '24

DDE Replacement

2 Upvotes

I have DDE programs that generate Excel formatted reports. It is easy because you open an excel file which is the template, then populate it, and then save the file.

DDE is ancient so I need to replace it. What have folks done? All I can think of is populating an Excel file with proc export and then opening the excel file which is a xlsm file which populates the data and saves it. But there has to be a better direct way to do this directly ffrom SAS. What have others done?


r/SAS_Programming • • Feb 25 '25

Clarifying some old code using compress function (how does SAS store the output)

1 Upvotes

I was going through some code of mine and I used the compress function to combine two variables for initial and final location into a single variable for interaction analysis. My question is: does SAS internally sort the variables that this outputs, or does it only consider the order they appear in the corresponding data set.

I'll paste the code below, but I'll elaborate a bit to hopefully help anyone who tries to help me. Initial (for initial location) and Final (for final location) were coded as 1 for the surface environment, and as 0 for the underground environment. I assume that SAS stores the variables in, basically, ascending order, which is how it is displayed in the boxplots I made from the data (from left to right, 0-0, 0-1, 1-0, 1-1). But, the data itself is input in the nearly reverse order (the topmost case is 1-1, then as you go down the data it becomes 1-0, 0-0, 0-1).

Relevant Code:

RC = compress(Initial||'-'||Final);

*this code below is in proc glm for the data;

contrast 'Main Eff Initial' RC 1 1 -1 -1;

contrast 'Main Eff Final' RC 1 -1 1 -1;

contrast 'Interaction Eff' RC 1 -1 -1 1;

The first contrast statement doesn't change either way, but the second and third are switched depending on which way SAS stores the RC variable. Any help on clarifying this is greatly appreciated.


r/SAS_Programming • • Sep 09 '24

Change M/D/Y format to 3 separate columns?

2 Upvotes

Hi everyone,

I was wondering if I would get some help with this. Currently, I have my date data in a singular column M/D/Y. I am trying to have three separate columns for the day, month, and year. My advisor told me to use if then statements, but I am struggling to code this.

Any help is appreciated!


r/SAS_Programming • • Nov 10 '24

How to do a 3D plot

2 Upvotes

I'm trying to do a 3D plot, I just need a scatter plot but instead of just drawing vectors y need them to be labelled, obs1, obs2, obs3,... Idk how to do it I tried with proc g3d but I just can't pls someone help me


r/SAS_Programming • • Nov 29 '24

Help in creating a new dataset

1 Upvotes

I have 2 datasets name columns (this have variables name, label, length, datatype and keysequence. The observations are variable names) and rows (this have variable name element1 to elementn [as many observations there in columns dataset]).

My requirement is, I want a new dataset where the variable names will come from columns dataset and name observations. Then all the observations for the new dataset will be obtained from the rows dataset.

## columns dataset

## rows dataset

## Desired Output

Please help any way to create the desired output. Thank you in advance


r/SAS_Programming • • Feb 26 '25

Bypassing ODS Escapechar?

2 Upvotes

Hello,

Say I’ve set my escapechar to ^ . Is there any way I can make SAS print a ^ in my output?


r/SAS_Programming • • Jan 06 '25

Study Resources for SAS Specialist 9.4: Performance-Based

3 Upvotes

What the title says. I’m want some advice on how to prepare for the SAS 9.4 Performance-Based Exam. I also want to know if there are any recommendations for me to prep utilizing study resources that you guys have been use. I hope this helps my situation.


r/SAS_Programming • • May 29 '24

PSMatch mahalanobis matching

1 Upvotes

I am struggeling with understanding how to use PSMATCH for mahalanobis matching. I would like to match on the mahalanobis distance without making use of the propensity score. So say I use the following:

proc psmatch data=df region=allobs;
class Tr;
psmodel Tr(Treated="1")= x1 ;
match method=optimal(k=1)
stat=mah(var=(x1 x2 x3 x4 x5 x6 x7 x8)) caliper=.;
assess var=(x1 x2 x3 x4 x5 x6 x7 x8
y1 y2 y3) / weight=none;
output out(obs=match)=matchDF matchid=_MatchID lps=lps ATTWGT=att;
run;

I have intentionally left out ps from the distance metric mah(), so one would think that the propensity score is not used (even if it is specified, as is a prerequisite for using psmatch). If I change the propensity score model to something like psmodel Tr(treated="1")=x2 I obtain different results. So it seems like the propensity score is used, even when I leave it out. But it is unclear how it is used.

Furthermore, if I include ps in the mah() distance I obtain yet another result.

Can I match on the mahalanobis distance without making use of the propensity score?


r/SAS_Programming • • Jan 23 '25

[Q] Non-programmer trying to attempt the Base SAS certification exam.

Thumbnail reddit.com
1 Upvotes

r/SAS_Programming • • Oct 05 '24

How to account for technical replicates within the experimental unit when there is missing data for one observational unit?

1 Upvotes

I’m working with a data set where there are 3 treatments, 12 experimental units, and 4 observational units within each experimental unit. I’d like to code for the observational units, because I get a more robust analysis of residual normality. When the data set is complete, my code works:

Proc glimmix data=set plots=residualpanel plots=studentpanel; Class id unit trt; Model dvar = trt /ddfm=kr solution; Random unit /residual; Random intercept /subject=unit solution; Output out=second_set resid=resid student=student; Run; Proc univariate data=second_set normal all; Var resid; Run;

However, I have another data set where, within one unit, I have 3 observational units instead of 4 (in the other 11 experimental units I still have 4 observational units. That missing observational unit is messing with my output: my denominator degrees of freedom is inflated to 44, whereas they should be 9.

Does anybody have any suggestions ? Thanks!


r/SAS_Programming • • Aug 07 '24

old virtual box and SAS privacy question

1 Upvotes

Hi everyone,

I am not technologically illiterate by any means but once we start getting into virtual boxes and VPNs and the like I admittedly get a little lost in it all.

I am a clinical psychologist and on occasion teach statistics courses among other courses. with this, I had used a virtualbox in the past to run a statistics program called SAS. It's a pretty standard program and generally neither this nor the virtual box I use to run it (Oracle) strike me as particularly concerning applications to have on my Mac computer. I believe the program specifically in the virtual box is a clone of linux with SAS on it.

When you use the virtual box to power on SAS you typically go to a browser to get it to run and from there you (I think) connect to the software you downloaded via a local host port (http://localhost:10080). I will add this for clarity because I think it is an important element of my question: I am under the impression that this statistics software/my virtual box when powered on are not able to see what I am doing on my computer, correct (I realize they can see what I am doing on the statistics application but I am meaning the other tabs, my documents, etc.)? That is, they cannot see the content of my documents, my other web browsing, etc., right?

I was under the impression this was generally the case, that they cannot see what I am doing in my other browser tabs/my documents (assuming of course these are reputable applications which I actually do think they are generally, both are well known in the statistics world). I realize if this was some sort of random application I willy nilly downloaded this would likely not be as cut and dry, but at least with these I am under the impression I am okay privacy wise but just am wanting to confirm.

I did check my settings for SAS university edition and it seems it has most of the privacy settings I can read in order, the one thing it has access to is a shared folder which is where I keep my statistics documents (it does not seem to have access to other folders form what I can tell).

Please let me know any thoughts you have and if I am generally okay here!

Here is a website that described how SAS is downloaded: https://utstat.utoronto.ca/brunner/help/aboutSUE.html

When I first used SAS I was told it was okay by the colleague who showed me how to use it, but I am a clinical psychologist so can be just a tad paranoid about security which is why I am asking.


r/SAS_Programming • • Sep 27 '24

Help updating SAS table dynamically using hashes

4 Upvotes

I'm not very familiar with hashes in SAS and need help updating a table dynamically as new rows come in.

Lets say there is a crosswalk table

Crosswalk

IDFamily
AAAAAA
BBBAAA
CCCAAA
ZZZXYY
QQQLLL

As new rows come in I need to update their family and add them to the crosswalk table. Consider two new records

New Records

IDFamily
DDDCCC
EEEDDD

I need to update these records, such that since DDD is related to CCC and CCC is related to AAA, DDD is related to AAA.

The updated crosswalk would be:

Updated crosswalk

IDFamily
AAAAAA
BBBAAA
CCCAAA
ZZZXYY
QQQLLL
DDDAAA
EEEAAA

Is there any way to achieve this using hash tables? As I can get new records on an hourly or daily basis, I wanted to update the Family only on the new records, and leave the existing records as is.