Hello,
What is the way to define a macro variable with a numerical date value?
In this case I need that SAS define macro variable start_SAS as value 22152 (Because 22152 is the numerical value of 25AUG2020)
What is the way to define it via %let please?
%let start_SAS='25AUG2020';
%put &start_SAS;
data ttt;
input x : date9.;
cards;
'20AUG2020'
'30AUG2020'
;
Run;
PROC SQL;
create table tbl as
select *
from ttt
where x>&start_SAS.
;
QUIT;
I know that I can write
%let start_SAS="25AUG2020"d;
But I prefer to see the real numeric value of the sas date .
> But I prefer to see the real numeric value of the sas date
Your log will be more legible with a human-friendly value such as '12AUG2020'd .
I know that I can write
%let start_SAS="25AUG2020"d;
But I prefer to see the real numeric value of the sas date .
Ideally, you'd use
%let start_dte=25AUG2020;
... where DATE > "&start_dte"d;
@ChrisNZ wrote:
I know that I can write
%let start_SAS="25AUG2020"d;
But I prefer to see the real numeric value of the sas date .
@FreelanceReinh has shown you how to get the numeric value.
But, there is almost no reason to generate the numeric value, which of course is uninterpretable to human eyes.
Lets say you have
%let mydate=25aug2020;
(note no quotes or other attributes of a date-literal).
Now you have a human-readable date which can always be used as a date literal by using double quotes, as in
data mysubset:
set mymaster;
where date>="&mydate"d;
...
run;
The point here is that when you surround a macrovar with double quotes SAS will not mask interpretation of the macrovar, i.e. the where statement becomes:
where date>="25aug2020"d;
But if you used the single quotes, (i.e. where date>='&mydate'd; ), there would be no resolution of the MYDATE macrovar.
Single quotes prevent macrovar resolution, double quotes don't.
%let start_SAS=%sysfunc(inputn(25AUG2020,date9.));
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.