DATA Step, Macro, Functions and more

macro logic call missing()

Accepted Solution Solved
Reply
Valued Guide
Posts: 858
Accepted Solution

macro logic call missing()

I have two pieces of code below.  The uncommented does not work, the commented does.  There is no error, the code runs but the fields in question are not missing.  If I use %syscall I get an error.  I've searched around the google and found that %syscall won't work with missing() but cannot find any alternative.  Any help is appreciated.

 

    %macro lag;
    %do i = 1 %to 11;
    _ldate&i = lag&i(record_date);    
    if intck('month',_ldate&i,record_date) > 11 then _ldate&i = .;
    if _count = &i then call missing(of _ldate&i-_ldate11); /* question refers to this line of the macro code */
    %end;
    %mend;
    %lag;
/*if _count = 1 then call missing(of _ldate1-_ldate11);*/
/*if _count = 2 then call missing(of _ldate2-_ldate11);*/


Accepted Solutions
Solution
‎10-01-2015 12:20 PM
Respected Advisor
Posts: 3,124

Re: macro logic call missing()

Your code looks fine and tests fine to me. This has to be something else.

 

%macro test;
%do i=1 %to 3;
if _n_=&i then call missing(of v&i-v3);
%end;
%mend test;
data test;
input v1-v3;
%test
cards;
1 2 3
4 5 6
5 6 7
;
run;

View solution in original post


All Replies
Solution
‎10-01-2015 12:20 PM
Respected Advisor
Posts: 3,124

Re: macro logic call missing()

Your code looks fine and tests fine to me. This has to be something else.

 

%macro test;
%do i=1 %to 3;
if _n_=&i then call missing(of v&i-v3);
%end;
%mend test;
data test;
input v1-v3;
%test
cards;
1 2 3
4 5 6
5 6 7
;
run;
Valued Guide
Posts: 858

Re: macro logic call missing()

I didn't think to test the call missing() seperately.  log 2-11 isn't available to remove on the first iteration and so on.  I seperated this step and it tests right now.

 

Thanks,

 

Mark

Super User
Posts: 10,550

Re: macro logic call missing()

Define "does not work".

Do you get an error? Post the whole code and the error from the log. With macros you may need to use option MPRINT to see the generated code.

 

No output?

Unexpected output? Them provide the whole code and example data that demonstrates the unexpected output and the expected.

Super User
Super User
Posts: 6,502

Re: macro logic call missing()

[ Edited ]

Perhaps the order of execution of the CALL MISSING and the assignment statements might be wrong?  Hard to tell without the whole program and some data.

You are generating the commands in this order:

 

_ldate1 = lag1(record_date);
if _count = 1 then call missing(of _ldate1-_ldate11);
_ldate2 = lag2(record_date);
if _count = 2 then call missing(of _ldate2-_ldate11);
_ldate3 = lag3(record_date);

 

If you use two %DO loops then you could generate in this order:

_ldate1 = lag1(record_date);
_ldate2 = lag2(record_date);
_ldate3 = lag3(record_date);
...
if _count = 1 then call missing(of _ldate1-_ldate11);
if _count = 2 then call missing(of _ldate2-_ldate11);
...

 

 

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 229 views
  • 0 likes
  • 4 in conversation