- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I know that I can write
%let start_SAS="25AUG2020"d;
But I prefer to see the real numeric value of the sas date .
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
> 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 .
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let start_SAS=%sysfunc(inputn(25AUG2020,date9.));
%put &start_sas ;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let start_SAS=%sysfunc(inputn(25AUG2020,date9.));