Dear All
first of all I would like to thank in advance all of You who would help me.
I usually perform my analyses after PS matching this way (I attach a sample code):
proc means data=matchedunpaired mean std; class group; var cont1; title 'cont1'; run; DATA mcont1; SET pairedcontinuous; WHERE Variables='cont1'; RUN; PROC TTEST data= mcont1; PAIRED _0*_1 ; RUN;
title 'Cat1'; proc freq data=matchedunpaired; table cat1*group/nopercent nocum norow; run; DATA mcat1; SET pairedcategorical; WHERE Variables='cat1'; RUN; PROC FREQ data=mcat1 ; TABLE _0*_1; EXACT mcnem; RUN;
I would like to build a macro (or some sort of automation) which might help me in creating new datasets (and consequentially performing new procedures) from a list of variables, without doing it manually.
Would it be possible?
Sincerely
Antonio
You could faster your code via BY statement.
For example:
DATA mcont1; SET pairedcontinuous; WHERE Variables='cont1'; RUN; proc sort data=mcont1; by Variables; run;
/*ODS OUTPUT ..... <---this could save the output as a dataset*/ PROC TTEST data= mcont1; by Variables; PAIRED _0*_1 ; RUN;
DATA mcat1; SET pairedcategorical; WHERE Variables='cat1'; RUN; proc sort data=mcat1; by Variables; run;
/*ODS OUTPUT ..... <---this could save the output as a dataset*/ PROC FREQ data=mcat1 ; by Variables; TABLE _0*_1; EXACT mcnem; RUN;
I'm sorry but this is far too vague for me to offer any assistance. Please be much more specific. Where would the new variables be used? What new data sets do you want? What list of variables are you referring to?
Still not clear. To write any code, I have to know the starting point, most likely a data set, and then the desired steps thereafter that produce the desired output. I think the desired output is clear, but where in all of these words you have written do I start?
Can you provide a sample data set that I can start from? Please provide the sample data set as working SAS data step code (examples and instructions), not as Excel files, not as copy and paste, only working SAS data step code is acceptable. Please provide an example list of variables.
So that page is using datasets defined in other pages and has a lot of steps. Please share a simple example dataset and the steps you are currently using to process it.
You can probably do it without having to perform code generation (aka making a macro). Instead you could probably just use BY group processing. If you have keys that uniquely identify the observations in your original dataset then PROC TRANSPOSE will convert multiple variables into multiple observations with the a variable indicating which observations came from which variable. So something like this will convert a wide dataset into a tall dataset.
proc transpose data=have out=tall(rename=(col1=value)) name=variable;
by key1 key2 ;
var var1 var2 var3 ;
run;
You can then sort it by the name variable and then do your later steps BY that variable. So for example if your first proc step was PROC MEANS it might look like this:
proc sort data=tall;
by variable key1 key2;
run;
proc means data=tall;
by variable;
var value;
run;
You could faster your code via BY statement.
For example:
DATA mcont1; SET pairedcontinuous; WHERE Variables='cont1'; RUN; proc sort data=mcont1; by Variables; run;
/*ODS OUTPUT ..... <---this could save the output as a dataset*/ PROC TTEST data= mcont1; by Variables; PAIRED _0*_1 ; RUN;
DATA mcat1; SET pairedcategorical; WHERE Variables='cat1'; RUN; proc sort data=mcat1; by Variables; run;
/*ODS OUTPUT ..... <---this could save the output as a dataset*/ PROC FREQ data=mcat1 ; by Variables; TABLE _0*_1; EXACT mcnem; RUN;
Thank you very much! this was exactly what I needed!!!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.