BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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;

 

 

7 REPLIES 7
Ronein
Meteorite | Level 14

I know that I can write 

%let start_SAS="25AUG2020"d;

But I prefer to see the real numeric value of the sas date .

ChrisNZ
Tourmaline | Level 20

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  .

 

ChrisNZ
Tourmaline | Level 20

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;

 

 

 

 

 

mkeintz
PROC Star

@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

--------------------------
FreelanceReinh
Jade | Level 19

Hello @Ronein,

 

Use the %SYSEVALF macro function:

%let start_SAS=%sysevalf('25AUG2020'd);
Ksharp
Super User
Or inpun() function.

%let start_SAS=%sysfunc(inputn(25AUG2020,date9.));

%put &start_sas ;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 3688 views
  • 2 likes
  • 6 in conversation