Hello
I want to create a macro variable called FromDate that will get the following value:
IF data set ttt exists then it will get value of max(BirthDate)
IF data set ttt doesn't exist then it will get value 22158 (Which represent 31Aug2020)
What is the way to do it please?
The code below is not working well, since data set ttt exists I expect to get value 22428 but I get value 22158.
Why?
data ttt;
input BirthDate : date9.;
cards;
15Aug2020'd
28MAY2021'd
;
Run;
%macro RRR;
%if %sysfunc(exist(ttt)) %then %do;
PROC SQL noprint;
select max(BirthDate) into : FromDate
from ttt
;
QUIT;
%end;
%else %do;
data _null_;
call symputx('FromDate','22158');
run;
%end;
%mend RRR;
%put &FromDate;
x
untested
%macro narf;
%global FromDate;
%if %sysfunc(exist(work.ttt)) %then %do;
proc sql noprint;
select max(BirthDate) into :FromDate trimmed
from work.ttt;
quit;
%end;
%else %do;
%let FromDate = '31Aug2020'd;
%end;
%mend;
untested
%macro narf;
%global FromDate;
%if %sysfunc(exist(work.ttt)) %then %do;
proc sql noprint;
select max(BirthDate) into :FromDate trimmed
from work.ttt;
quit;
%end;
%else %do;
%let FromDate = '31Aug2020'd;
%end;
%mend;
Where is this macro variable to be used?
You may run into scope issues of where this is defined not being available to where actually wanted.
What is wrong with my code?
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.