SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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);*/

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

4 REPLIES 4
Haikuo
Onyx | Level 15

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;
Steelers_In_DC
Barite | Level 11

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

ballardw
Super User

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.

Tom
Super User Tom
Super User

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);
...

 

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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