Why the error? Select in SAS macros

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

Why the error? Select in SAS macros

Hi,

Here is my code.

data two;

input one;

monyy=put(one,monyy5.);

datalines;

19232

;

run;

options mlogic mprint symbolgen;

%macro cal;

data three;

set two;

  select (monyy);

when ('AUG12') do;

%do i = 13 %to 1 %by -1;

EOM_DOD_&I. = EOM_DOD&I.; 

%END;                  

                      

%DO I=14 %TO 18 %BY 1;   

EOM_DOD_&I. = EOM_DOD&I.; 

%END; 

  otherwise;

  end;

run;

%mend;

%cal

Upon submitting the above code, iam getting below error, can you let me know the error?

MLOGIC(CAL):  Beginning execution.

MPRINT(CAL):   data three;

MPRINT(CAL):   set two;

MPRINT(CAL):   select (monyy);

MPRINT(CAL):   when ('AUG12') ;

MLOGIC(CAL):  %DO loop beginning; index variable I; start value is 13; stop value is 1; by value is -1. 

SYMBOLGEN:  Macro variable I resolves to 13

ERROR: Expecting "WHEN", "OTHERWISE", or "END".

SYMBOLGEN:  Macro variable I resolves to 13

MPRINT(CAL):   EOM_DOD_13 = EOM_DOD13;

MLOGIC(CAL):  %DO loop index variable I is now 12; loop will iterate again.

SYMBOLGEN:  Macro variable I resolves to 12

ERROR: Expecting "WHEN", "OTHERWISE", or "END".

SYMBOLGEN:  Macro variable I resolves to 12

MPRINT(CAL):   EOM_DOD_12 = EOM_DOD12;

MLOGIC(CAL):  %DO loop index variable I is now 11; loop will iterate again.

SYMBOLGEN:  Macro variable I resolves to 11

ERROR: Expecting "WHEN", "OTHERWISE", or "END".

SYMBOLGEN:  Macro variable I resolves to 11

MPRINT(CAL):   EOM_DOD_11 = EOM_DOD11;

MLOGIC(CAL):  %DO loop index variable I is now 10; loop will iterate again.

i execute above code with 200M rows, i can use If condition, but i read Select is efficient when compare to IF THEN, or shouldn't i use select statement in SAS Macros??

Please let me know your thoughts, and where is the error??? Thanks!


Accepted Solutions
Solution
‎10-24-2014 10:47 AM
Contributor alr
Contributor
Posts: 39

Re: Why the error? Select in SAS macros

Try to put an END before otherwise.

View solution in original post


All Replies
Solution
‎10-24-2014 10:47 AM
Contributor alr
Contributor
Posts: 39

Re: Why the error? Select in SAS macros

Try to put an END before otherwise.

Contributor
Posts: 39

Re: Why the error? Select in SAS macros

Thank you. Smiley Happy

Grand Advisor
Posts: 10,251

Re: Why the error? Select in SAS macros

Nothing to do with macros. You didn't close the do loop started by when ('AUG12')

set two;

  select (monyy);

when ('AUG12') do;

%do i = 13 %to 1 %by -1;

EOM_DOD_&I. = EOM_DOD&I.; 

%END;                  

                      

%DO I=14 %TO 18 %BY 1;   

EOM_DOD_&I. = EOM_DOD&I.; 

%END; 

end; /* to close the when ('AUG12') do section */

  otherwise;

  end;

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 301 views
  • 3 likes
  • 3 in conversation