BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
helloSAS
Obsidian | Level 7


Hi, I came across a wierd situation. Can someone explain me this?

One of our prod jobs is using %let statement as below and it works

%let rundt = today();

however, when i run the same &rundt resolves to today() and not actual date of today.

I've to use %let rundt = %sysfunc(today());

why is it that it works without %sysfunc in other jobs?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The statements do the same thing, whether it is in your job or in a production job.  Whenever you see this statement:

%let rundt = today();

the value of &RUNDT is not a number, but is the 7 characters "today()".

What you are not observing is how the production program uses &RUNDT.  For example, it may use this statement in a DATA step:

date = &RUNDT;

In that case, the statement resolves into:

date = today();

When that statement appears in a DATA step, it executes and DATE receives the proper numeric value.

View solution in original post

5 REPLIES 5
Astounding
PROC Star

The statements do the same thing, whether it is in your job or in a production job.  Whenever you see this statement:

%let rundt = today();

the value of &RUNDT is not a number, but is the 7 characters "today()".

What you are not observing is how the production program uses &RUNDT.  For example, it may use this statement in a DATA step:

date = &RUNDT;

In that case, the statement resolves into:

date = today();

When that statement appears in a DATA step, it executes and DATE receives the proper numeric value.

helloSAS
Obsidian | Level 7

Thank you!

One more question

Why am i not able to use below statement?

%let month1x = %sysfunc(month(today()));

where as, I'm able to use

data _null_ ;

call symput('month1x',month(today()));

run;

Astounding
PROC Star

You'll need to use %SYSFUNC for each function ... once for MONTH and once for TODAY.  I hope I get the number of parentheses correct:

%let month1x = %sysfunc(month(%sysfunc(today())));

helloSAS
Obsidian | Level 7

Thank you!

I was able to get same results using both ways below. However, I had to use  ' ' quotes around month in intnx function for call symput and not for %sysfunc.

Can you tell me the reason why?

  %let month2 = %sysfunc(month(%sysfunc(intnx(month,%sysfunc(today()),-1))));
  %put &month2;

   data _null_;
  call symput ('month1',month(intnx('month',today(),-1)));
  run;
  %put &month1;

Astounding
PROC Star

Except in rare cases where a number is required, macro language assumes all strings are text.  Easy examples:

%let name=Fred;

%let name="Fred";

The first statement assigns &NAME a 4-character value.  The second assigns &NAME a 6-character value.  The quotes are not needed to identify a string, and so become part of the value assigned to &NAME.

You're looking at the same principle, but in a more complex setting.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 5 replies
  • 1243 views
  • 8 likes
  • 2 in conversation