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);
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.