BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
antor82
Obsidian | Level 7

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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;

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
antor82
Obsidian | Level 7
Dear PaigeMiller

Thank you for your prompt reply.

I’ve an original dataset which I used for unmatched analyses. Then I’ve performed my PS matching procedure and I’ve obtained an output with all 1:1 matched cases.

I’ve transposed all the data into two different datasets (one for continuous variables, one for categorical ones) and performed my paired analyses following the steps described into the online guide (https://documentation.sas.com/doc/en/statug/15.2/statug_psmatch_examples09.htm).

My question is: should I repeat manually all these steps for each single variable or is there some syntax that might do this for me (obviously specifying the list of variables to be included)?

Thanks in advance

Antonio

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Tom
Super User Tom
Super User

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;
Ksharp
Super User

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;
antor82
Obsidian | Level 7

Thank you very much! this was exactly what I needed!!!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 552 views
  • 0 likes
  • 4 in conversation