Help using Base SAS procedures

Multiple do loop to be used in another macro

Reply
New Contributor
Posts: 3

Multiple do loop to be used in another macro

Hi, folks. I am trying to run this code. The purpose is to use the variables of var list which are changing over time in another macro. 

%let DEAScorelist=x501 x502 x503;

%macro Do_Forme:
data _null_;
%do i=1 to %sysfunc(coutw(&DEAscorelist));
 %let DEA_score= %scan(&DEAscorelist,&i);
	length line $300;
		%do DTS = 2007 to 2014;
			UTS=DTS+&PT.-1;
			DHS=DTS+&PT.;
			UHS=DTS+&PT.+&PH.-1;
			SDTS=put(DTS,4.);
			SUTS=put(UTS,4.);
			SDHS=put(DHS,4.);
			SUHS=put(UHS,4.);
			DT=substr(SDTS,3,2);
			UT=substr(SUTS,3,2);
			DH=substr(SDHS,3,2);
			UH=substr(SUHS,3,2);
    	line = cats('%nrstr(%merge_scores_results(DTS=', DTS, ',UTS=', UTS, ',DHS=', DHS, ',UHS=', UHS, ',DT=', DT, ',UT=',UT, ',DH=' ,DH, ',UH=' ,UH, ',DEA_score=' ,DEA_score, '));');
    	call execute(line);
  		%end;
  %end;
	run;
%mend Do_Forme;



%Do_Forme;

 Would you please help.

 

Thanks

 

Super User
Posts: 17,819

Re: Multiple do loop to be used in another macro

What's the question?

New Contributor
Posts: 3

Re: Multiple do loop to be used in another macro

Reeza. It doesn't work.
New Contributor
Posts: 3

Re: Multiple do loop to be used in another macro

Thanks for your reply. Actually, I receive the following warning message:

WARNING: Apparent invocation of macro DO_FORME not resolved.

Super User
Posts: 6,936

Re: Multiple do loop to be used in another macro


Mohammad wrote:

Thanks for your reply. Actually, I receive the following warning message:

WARNING: Apparent invocation of macro DO_FORME not resolved.


If you get that, the compilation of the macro failed. Probably because of the TO instead of %TO.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 6,936

Re: Multiple do loop to be used in another macro

I guess your mixing macro code with datastep code causes the issue.

Since (as it seems to me) all you want to do is call a macro repeatedly with call execute, the loops can be done with data step code alone.

 

BTW, "it does not work" is on par with "a bicycle was stolen in Beijing". Don't force us to make guesses.

 

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,081

Re: Multiple do loop to be used in another macro

A %DO loop should use %TO.

 

Super User
Posts: 10,497

Re: Multiple do loop to be used in another macro

In addition to likely macro and datastep loop confusion you are referencing macro variables PT  and PH  with out any clue as to what they may look like. So a failure for your DO_Forme macro may fail because of values of those variables.

 

From what I see inside your macro there is no need for macro loop processsing.

 

You should run your macro with the system options MPRINT and SYMBOLGEN at least once. You may get some ideas of where the actual problem is as well as hints as to why you don't want the %do DTS to be a macro loop. Note that %do DTS creates a macro varaible. So all of your other references to DTS are a missing datastep variable. And any missing value + something will be missing.

Ask a Question
Discussion stats
  • 7 replies
  • 266 views
  • 1 like
  • 5 in conversation