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

I have a macro variable declared earlier as (it will be manually changed as needed):

 

%let monthly_update = 1;

 

 

Later on I would like to conditionally make a dataset as (not sure of the code but you will get the picture):

 

if &monthly_update = 1 then

     data final;

          set predata;

          monthlyupdate = 1;

    run;

else

     data final;

           set predata;

    run;

end

 

 

thanks in advance!!

-Bill

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
%macro dothis;
%if &monthly_update = 1 %then %do;
     data final;
          set predata;
          monthlyupdate = 1;
    run;
%end;
%else %do;
     data final;
           set predata;
    run;
%end;
%mend;


%let monthly_update=1;
%dothis

or even simpler:

 

%macro dothis;

     data final;
          set predata;
          %if &monthly_update=1 %then monthlyupdate = 1%str(;);
    run;

%mend;


%let monthly_update=1;
%dothis

If you have SAS 9.4 TS1M5 or later, you don't even need a macro, the %if %then %else in the first example can be used in open code.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
%macro dothis;
%if &monthly_update = 1 %then %do;
     data final;
          set predata;
          monthlyupdate = 1;
    run;
%end;
%else %do;
     data final;
           set predata;
    run;
%end;
%mend;


%let monthly_update=1;
%dothis

or even simpler:

 

%macro dothis;

     data final;
          set predata;
          %if &monthly_update=1 %then monthlyupdate = 1%str(;);
    run;

%mend;


%let monthly_update=1;
%dothis

If you have SAS 9.4 TS1M5 or later, you don't even need a macro, the %if %then %else in the first example can be used in open code.

--
Paige Miller

hackathon24-white-horiz.png

Join the 2025 SAS Hackathon!

Calling all data scientists and open-source enthusiasts! Want to solve real problems that impact your company or the world? Register to hack by August 31st!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 808 views
  • 1 like
  • 2 in conversation