How do i output in a macro a unique output file/dataset for each cycle?

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

How do i output in a macro a unique output file/dataset for each cycle?

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.

 


Accepted Solutions
Solution
‎09-22-2016 06:04 AM
Respected Advisor
Posts: 3,837

Re: How do i output in a macro a unique output file/dataset for each cycle?

[ Edited ]

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


All Replies
Grand Advisor
Posts: 17,411

Re: How do i output in a macro a unique output file/dataset for each cycle?

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...

Solution
‎09-22-2016 06:04 AM
Respected Advisor
Posts: 3,837

Re: How do i output in a macro a unique output file/dataset for each cycle?

[ Edited ]

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;

 

Contributor
Posts: 22

Re: How do i output in a macro a unique output file/dataset for each cycle?

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);
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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