I need this macro to repeat the data processing for each set of variable ending in 0,1,2, 3,4,5,6,7,8,9,10 and 13. I can getting the following error message Required operator not found in expression: &b. in (0,1,2,3,4,5,6,7,8,9,10,13)
%macro life_events();
%let b=0; /*initializ counter*/
%do %while (&b <=13);
%put &b;
%if &b. in (0,1,2,3,4,5,6,7,8,9,10,13) %then %do;
array event(18) evt1-evt18;
array evtorig[18] startne&b worktrb&b quitjob&b workloa&b prtunem&b moneypr&b
worsrel&b relaten&b seripro&b childmo&b respcar&b legalpr&b creldie&b
closdie&b selfvio&b famlvio&b physill&b majeven&b;
%do e = 1 %to 18;
event(e) = evtorig[e];
%if event(e) lt 0 %then event(e) = .;
%end;
array count(18) cnt1-cnt18;
array eventC[18] evt1-evt18;
%do c = 1 %to 18;
count(c) = eventC[c];
%if count(c) lt 2 %then count(c) = .;
%end;
EVNTNUM&b = (n(of cnt1-cnt18));
array very(18) vry1-vry18;
array eventV[18] evt1-evt18;
%do v = 1 %to 18;
very(v) = eventV[v];
%if very(v) lt 4 %then very(v) = .;
%end;
EVNTVRY&b = (n(of vry1-vry18));
EVNTCAT&b = evntvry&b.;
%if EVNTVRY&b ge 2 %then evntcat&b = 2;
NonMiss = n(of evt1-evt18);
%if NonMiss lt 14 %then %do;
EVNTNUM&b = .;
EVNTVRY&b = .;
EVNTCAT&b = .;
%end;
%end;
%let b=%sysevalf(&b+1); /*increment b*/
%end;
%mend life_events;
If you want to use the word IN to be an operator in macro code you need to tell the macro processor that in advance.
%macro life_events() / minoperator mindelimiter=',' ;
...
%if &b. in 0,1,2,3,4,5,6,7,8,9,10,13 %then %do;
...
But it is not needed in this case.
%do b=0 %to 13 ;
%if not (&b=11 or &b=12) %then %do;
...
%end;
%end;
Ugh. You commit the (sadly common) cardinal sin of trying to handle data with the macro preprocessor, which is for creating dynamic code.
Since you already know how to define arrays, why don't you just use the necessary data step do loops to iterate through the arrays? As far as I can see it, there is absolutely no need for macro processing here.
What code are trying to have that macro generate?
I think you will have get error messages since it appears to be generating the same ARRAY multiple times.
If you want to use the word IN to be an operator in macro code you need to tell the macro processor that in advance.
%macro life_events() / minoperator mindelimiter=',' ;
...
%if &b. in 0,1,2,3,4,5,6,7,8,9,10,13 %then %do;
...
But it is not needed in this case.
%do b=0 %to 13 ;
%if not (&b=11 or &b=12) %then %do;
...
%end;
%end;
Thank you so much. This made the difference.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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: