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!
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!
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.