l*********s 发帖数: 5409 | 1 I am having some very weird bug while trying to write a macro that can
expend the short hand notion like var1--var11 used in SAS.
The "shorthand" macro works fine on its own, but fails to work when called
by the "formula" macro. The error message seems to say that "the set
statement in the data step is not valid or not in proper order", what's
going on?
Many thanks!
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
data svtest;
input a au1 d1 d2 d3 d4 d5 bu1 cu1 bu2 cu2 bu3 cu3 @@;
cards;
1 2 3 4 5 6 7 8 9 10 11 12 13
;
run;
/* set up enviroment */
%let ds= work.svtest;
%let varlst=
au1 (d1-d4) bu1 (cu1 - cu3 )
;
option mprint mlogic;
%macro shorthand(argstr, ds);
data varnamelst;
%put &ds.;
set &ds.(obs=1 firstobs=1 keep= &argstr. );
run;
proc transpose data=varnamelst out=varnamelst; run;
proc sql noprint; select _NAME_ into :expendedvarlst separated by " " from
varnamelst; quit;
%mend;
%macro formula(orgarg,ds);
%global resl;
%let covars=%upcase(%bquote(&orgarg.));
%let resl=;
%do %while( %index(%bquote(&covars.),-) > 0);
%let i=%index(%bquote(&covars.),-);
%put i= &i.;
%let word1 = %scan(%bquote(%substr(%bquote(&covars.),1,&i.)), -1);
%put word1 = &word1.;
%let pos1 = %index(%bquote(&covars.), &word1.);
%put pos1 = &pos1.;
%let resl=%substr(%bquote(&covars.),1,%EVAL(&pos1. -1));
%put resl = &resl.;
%let word2 = %scan(%bquote(%substr(%bquote(&covars.),%EVAL(&i.+1))),1);
%%put word2 = &word2.;
%let pos2 = %EVAL(%index(%bquote(&covars.), &word2.)+%length(&word2.) );
%put pos2 = &pos2.;
%let len =%EVAL(&pos2.-&pos1.);
%put len = &len.;
%let passingval = %substr(%bquote(&covars.), &pos1.,&len.);
%put passing parameter = &passingval.;
%shorthand(&passingval.,&ds.);
%let resl= %bquote(&resl.) %bquote(&expendedvarlst.);
%put resl = &resl.;
%let covars= %substr(%bquote(&covars.),&pos2.);
%put covars = %bquote(&covars.);
%end;
%let resl= %bquote(&resl.) %bquote(&covars.);
%put return = &resl.;
%mend;
%formula(&varlst., svtest);
%let expendedvarlst=;
%shorthand(D1-D4,work.svtest);
%put &expendedvarlst; | p******r 发帖数: 1279 | 2 not sure if this works but maybe you shall call it like
%shorthand(argstr=&passingval.,ds=&ds.);
instead of
%shorthand(&passingval.,&ds.);
and it is not a good practice to have a %put statement between data step in
your %shorthand macro, though it may not be the problem.
【在 l*********s 的大作中提到】 : I am having some very weird bug while trying to write a macro that can : expend the short hand notion like var1--var11 used in SAS. : The "shorthand" macro works fine on its own, but fails to work when called : by the "formula" macro. The error message seems to say that "the set : statement in the data step is not valid or not in proper order", what's : going on? : Many thanks! : //////////////////////////////////////////////////////////////////// : //////////////////////////////////////////////////////////////////// : data svtest;
| l*********s 发帖数: 5409 | 3 Thank you very much! I tried your suggestion and the problem persists, 5555
T__T
in
【在 p******r 的大作中提到】 : not sure if this works but maybe you shall call it like : %shorthand(argstr=&passingval.,ds=&ds.); : instead of : %shorthand(&passingval.,&ds.); : and it is not a good practice to have a %put statement between data step in : your %shorthand macro, though it may not be the problem.
| o****o 发帖数: 8077 | 4 dude, you put two %% in this line:
%let word2 = %scan(%bquote(%substr(%bquote(&covars.),%EVAL(&i.+1))),1);
---> %%put word2 = &word2.;
%let pos2 = %EVAL(%index(%bquote(&covars.), &word2.)+%length(&word2.) );
remove one % and you are all set | a*****3 发帖数: 601 | 5 When I saw the 'baozi' in subject line , i was so excited and turn on SAS9.1
.3 to earn some baozi for dinner; When I saw oloolo posted a message, i
shut down SAS9.1.3 going to bed with empty stumach. | l*********s 发帖数: 5409 | 6 太谢谢了!
【在 o****o 的大作中提到】 : dude, you put two %% in this line: : %let word2 = %scan(%bquote(%substr(%bquote(&covars.),%EVAL(&i.+1))),1); : ---> %%put word2 = &word2.; : %let pos2 = %EVAL(%index(%bquote(&covars.), &word2.)+%length(&word2.) ); : remove one % and you are all set
|
|