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
%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.
%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.
thanks!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.