01-07-2017 04:44 PM
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.
01-08-2017 04:15 AM
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.
01-07-2017 06:27 PM
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.
01-09-2017 11:16 AM
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.