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

I have a macro that is looping through datafiles from different years for a proc mean. I want it to run with a different var statement depending on which year it is currently looping through.  At the moment, my code looks like this:

%macro varcheck;

     %do i = &yrmin %to &yrmax;

          %let yr = %substr(&i.,3,2);

          proc means n mean median max data=&lib..&stem.&yr.;

               %if 2000 <= &i <= 2011 %then

                    vars variables;

             %else %if 2012 <= &i <= 2013 %then

                    vars other variables;

             ;

          run;

     %end;

%mend varcheck;

%varcheck;

When I run the code, however, the program returns the following on years 2012 and 2013:

SYMBOLGEN:  Macro variable I resolves to 2012

MLOGIC(VARCHECK):  %IF condition 2000 <= &i <= 2011 is TRUE

It works if I replace the if conditions with &i = 2000 or &i = 2001 etc., but that can get pretty cumbersome. Is there a way to get this to resolve correctly, or am I stuck with the clunky way?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

THIS <= &i <=  does not work as expected in macro language.

Change it to

%if  2000 <= &i  AND &i  <= 2011 or some variation thereof.

View solution in original post

1 REPLY 1
Reeza
Super User

THIS <= &i <=  does not work as expected in macro language.

Change it to

%if  2000 <= &i  AND &i  <= 2011 or some variation thereof.

sas-innovate-2024.png

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.

 

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.

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
  • 1 reply
  • 660 views
  • 0 likes
  • 2 in conversation