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);*/
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;
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;
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
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.
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);
...
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.