由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - Weird SAS macro bugs, 包子重谢!
相关主题
请教macro的一个小程序,sas 代码问题
请教一个macro的问题【包子】求问个简单sas macro问题
求助:一个SAS小程序一个常见的问题
请教一个SAS 数据分配问题SAS Macro Function
请教一个SAS Macro的问题请教一道SAS MACRO编程的问题。怎么都不明白。谢谢
SAS help : how to macro odssas macro, proc sql 问题
SAS macro questionStupid SAS programming style is driving me crazy....
sas macro 问题用尽心思做好了一个macro
相关话题的讨论汇总
话题: bquote话题: covars话题: resl话题: let话题: put
进入Statistics版参与讨论
1 (共1页)
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

1 (共1页)
进入Statistics版参与讨论
相关主题
用尽心思做好了一个macro请教一个SAS Macro的问题
Need advice on SAS macro debuggingSAS help : how to macro ods
ask for help (urgent): A SAS questionSAS macro question
再来请教,在SAS中如何得到下面的结果?sas macro 问题
请教macro的一个小程序,sas 代码问题
请教一个macro的问题【包子】求问个简单sas macro问题
求助:一个SAS小程序一个常见的问题
请教一个SAS 数据分配问题SAS Macro Function
相关话题的讨论汇总
话题: bquote话题: covars话题: resl话题: let话题: put