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

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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;

 

View solution in original post

3 REPLIES 3
Reeza
Super User

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. 

https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-run-multiple-regres...

Patrick
Opal | Level 21

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;

 

Dcicantab5
Obsidian | Level 7

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);

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 839 views
  • 2 likes
  • 3 in conversation