BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mathias
Quartz | Level 8

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;

?

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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_

View solution in original post

5 REPLIES 5
Ksharp
Super User

You don't have argument in your macro.

%macro test(ds);

          %missvars(&ds)

     %mend test;

mathias
Quartz | Level 8

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.

data_null__
Jade | Level 19

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_

Astounding
PROC Star

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 892 views
  • 3 likes
  • 4 in conversation