Hi,
Somebody knows why %missvars works fine in a normal program
%missvars(ds); /* http://www.datasavantconsulting.com/roland/missvars.sas */
and doesn't in a macro called with call execute routine
%macro test;
%missvars(ds
%mend test;
data _null_;
set NRC_germ;
call execute('%test('||trim(Germ)||')');
run;
?
You probably need to delay execution of the CALL EXECUTEd macro until after the data step that is doing the CALL EXECUTEing finishes.
call execute('%nrstr(%germvars('....
Message was edited by: data _null_
You don't have argument in your macro.
%macro test(ds);
%missvars(&ds)
%mend test;
Right,
but this is just a simplified code I wrote quickly. No repercussions here.
This is the actual code if you need it (but it'll confuse the question)
(I'am trying to change %missvars with %dropmiss right now but it's the same issue : it produces weird logs with no errors (cf. attached log) ) :
data NRC_GERMVARIABLE(where=(Germ ne ""));
length Source Germ Variable $30;
run;
%macro germvars(subject);
%put 0--- subject=&subject;
%put 1--- select germ ;
data WORK.NRC_VARIABLES1;
set ID_DATA.NRC_CLEAN;
where Subject="&subject";
run;
%put 2--- remove empty variables ;
/* %missvars(NRC_VARIABLES1);
%put &_miss_;
data NRC_VARIABLES2;
set NRC_VARIABLES1(drop=&_miss_);
run;*/
%dropmiss(NRC_VARIABLES1,NRC_VARIABLES2);
%put 3--- list variables vertically ;
proc transpose
data= WORK.NRC_VARIABLES2 (obs=1)
out= WORK.NRC_VARIABLES3(rename=(_NAME_=Variable) drop=_LABEL_);
var _all_;
run;
%put 4--- append them in NRC_GERMVARIABLE ;
data WORK.NRC_VARIABLES4 (drop=col1);
length col1 $20;
set WORK.NRC_VARIABLES3;
col1=col1;
Source="NRC";
Germ="&subject";
run;
PROC APPEND BASE=NRC_GERMVARIABLE DATA= WORK.NRC_VARIABLES4 FORCE NOWARN;
/* */
%mend germvars;
data _null_;
set NRC_germ;
call execute('%germvars('||trim(Germ)||')');
run;
(this forum still needs sas syntaxing)
from the log it looks like de the order of execution is not right.
You probably need to delay execution of the CALL EXECUTEd macro until after the data step that is doing the CALL EXECUTEing finishes.
call execute('%nrstr(%germvars('....
Message was edited by: data _null_
CALL EXECUTE is tricky. The standard actions it takes are to perform any macro language statements immediately. However, any generated DATA and PROC statements have to wait until the currently executing DATA step completes. So all your %PUT statements execute right away, before the generated DATA and PROC steps have run.
Your code is probably breaking down at the point this statement appears: %put &_miss_;
We don't see the definition of the interior macros, but it is fairly certain that this %PUT statement executes before &_miss_ has been created. Without seeing the macros nor the error messages, it's a little difficult to say. But it seems likely that this is the issue.
The usual remedy to delay macro execution when using CALL EXECUTE is to apply the %NRSTR function within the CALL EXECUTE statement.
Good luck.
That's it, %NRSTR
Thanks !
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: