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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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.

 

Tom
Super User Tom
Super User

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.

Tom
Super User Tom
Super User

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;
Stat_prevmed
Fluorite | Level 6

Thank you so much.  This made the difference.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 4 replies
  • 4150 views
  • 1 like
  • 3 in conversation