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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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