BookmarkSubscribeRSS Feed
itmightbeharry
Fluorite | Level 6

Hello everyone:

 

Could someone please assist me to write a macro in SAS Studio that will allow me to create temporary datasets and run proc logistic for three pairwise comparisons? I would like to have the datasets be tmp13, tmp23, and tmp12, respectively, with the numbers representing treatment assignments (i.e., trt01pn can equal 1, 2, or 3). Within each dataset, I need to create a variable trt such that if trt01pn = the first number in the data step after tmp then trt = 1;  else if trt01pn = the second number in the data step after tmp then trt = 0. I later need to create three datasets, say data13, data23, and data12, in which one of tmp13, tmp23, or tmp12 is each used one time together with tmpcopy0 and tmpcopy1. The trt variable = 0 for tmpcopy0 and 1 for tmpcopy1, so these will not vary by treatment. Next, I need to use each of data13, data23, and data12 in proc logistic with each producing a separate output, for instance out = pred13 in one proc logistic, out = pred23 in another, and out = pred12 in the last logistic. Lastly, from pred13, pred23, and pred12, I need to create two datasets each, such as pred113 and pred013 for pred13, pred123 and pred023 for pred23, and pred112 and pred012 for pred12. I have placed the code needed for the trt01pn = 1 vs trt01pn = 3 comparison below, realizing I could do the above with a series of copy and pastes, but want to learn how to write this through a macro. Thank you for your help! 🙂

 

data tmp13;
set score;
newdata = 0;
if trt01pn = 1 then trt = 1;
else if trt01pn = 3 then trt = 0;
run;
 
data tmpcopy0;
set score;
newdata = 1;
trt = 0;
run;
 
data tmpcopy1;
set score;
newdata = 1;
trt = 1;
run;
 
data data13;
set tmp13 tmpcopy0 tmpcopy1;
run;
 
proc logistic data=data13;
model ybin (event='1') = trt base;
output out=pred13 p=prob;
run;
 
data pred113;
set pred13;
where newdata=1 and trt=1;
rename pred=pred1;
run;
 
data pred013;
set pred13;
where newdata=1 and trt=0;
rename pred=pred0;
run;
1 REPLY 1

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1 reply
  • 442 views
  • 2 likes
  • 2 in conversation