Hi,
How do i output in a macro a unique output file/dataset for each cycle, to the temporary work folder, so that it will be available for use in a second macro?
%macro speed(univariatecate, factor); proc logistic data=work.sd; class gender &univariatecate. (ref="0")/param=ref; model Outcome(event='1')=Age_yr_ gender &univariatecate. &factor./selection=none; output out=sdcrossvalidm2 predprobs=crossvalidate; run; %mend; %speed(bleed, PR); %speed(bleed, ALT); %speed(bleed, AST); %macro speedcv(univariatecate, factor); proc logistic data=work.sdcrossvalidm2 plots(only label)=all; class gender &univariatecate. (ref="0")/param=ref; model Outcome(event='1')=Age_yr_ gender &univariatecate. &factor./selection=none; roc pred=xp_1; roccontrast; ods output rocassociation=SDcrossvalidatedm2; run; %mend; %speed(bleed, PR); %speed(bleed, ALT); %speed(bleed, AST); ods graphics off;
In the code above (which don't work), the first macro do not output unique files for each cycle {(bleed,PR), (bleed,ALT), (bleed,AST)}. I want to make unique files so that it will be available to the second macro which crossvalidates the first.
Help & guidance most appreciated!
Thank you,
Saiful.
As for the suggestion to create unique table names, code as below used at the begining of your first macro could do the job.
%global my_dsname;
%let my_dsname=t_%sysfunc(datetime(),b8601dt15.0);
And then in your 2nd macro once you're done with the data set and to keep WORK tidy, you could delete the ds using code as below:
proc datasets lib=%scan(work.&my_dsname,-2,.) nolist nowarn;
delete %scan(&my_dsname,-1,.);
run;quit;
Give your output files unique names....come up with some sort of naming convention that you can use in your second macro.
OR transpose your data so that PR/ALT/AST are by groups and then use BY group processing.
As for the suggestion to create unique table names, code as below used at the begining of your first macro could do the job.
%global my_dsname;
%let my_dsname=t_%sysfunc(datetime(),b8601dt15.0);
And then in your 2nd macro once you're done with the data set and to keep WORK tidy, you could delete the ds using code as below:
proc datasets lib=%scan(work.&my_dsname,-2,.) nolist nowarn;
delete %scan(&my_dsname,-1,.);
run;quit;
Thanks guys, both advices got me thinking, hence the following worked!:
%macro speed(univariatecate, factor, my_dsname); proc logistic data=work.sd; class gender &univariatecate. (ref="0")/param=ref; model Outcome(event='1')=Age_yr_ gender &univariatecate. &factor./selection=none; output out=&my_dsname. predprobs=crossvalidate; run; %mend; %speed(bleed, PR, bleedpr); %speed(bleed, ALT, bleedalt); %speed(bleed, AST, bleedast); %macro speedcv(univariatecate, factor, my_dsname); proc logistic data=&my_dsname. plots(only label)=all; class gender &univariatecate. (ref="0")/param=ref; model Outcome(event='1')=Age_yr_ gender &univariatecate. &factor./selection=none; roc pred=xp_1; roccontrast; run; %mend; %speedcv(bleed, PR, bleedpr); %speedcv(bleed, ALT, bleedalt); %speedcv(bleed, AST, bleedast);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.