DATA Step, Macro, Functions and more

how do i create a macro variable of todays date like this 20170424

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

how do i create a macro variable of todays date like this 20170424

[ Edited ]

I need todays date in a macro variable like that.

Thanks!

 

 I tried yymmdd8. but it came out like mmddyy8.  (per chart below...)

 

Untitled.png


Accepted Solutions
Solution
‎04-24-2017 03:09 PM
PROC Star
Posts: 308

Re: how do i create a macro variable of todays date like this 20170424


%let todaysDate = %sysfunc(today(), yymmddn8.);
%put &todaysDate;

View solution in original post


All Replies
Solution
‎04-24-2017 03:09 PM
PROC Star
Posts: 308

Re: how do i create a macro variable of todays date like this 20170424


%let todaysDate = %sysfunc(today(), yymmddn8.);
%put &todaysDate;

Super User
Posts: 19,878

Re: how do i create a macro variable of todays date like this 20170424

You can also look into &SYSDATE which is an automatic macro variable. Depending on how you're submitting a job, this may or may not be helpful.

 

http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n08zfkx3lmiagpn11...

Contributor
Posts: 46

Re: how do i create a macro variable of todays date like this 20170424

[ Edited ]

i was hoping for a solution of this variety (which doesn't work...)

After 5 years of sas work, I am still clueless on dates.....

 

data _null_;

   format dt mmddyy10.;

   dt= date();

   call symput('dt',trim(left(input(dt,mmddyy10.)));

   run;

 

%put &dt;

run;

 

 

  

Super User
Posts: 19,878

Re: how do i create a macro variable of todays date like this 20170424

Dates are numbers. To convert it to a character, use PUT with the format you'd like it to appear with. 

 

Your solution was overcomplicated. Here's the simplified version, note I'm using CALL SYMPUTX() to create a global macro variable with no trailing spaces.

 

data _null_;
   call symputx('dt',put(date(),mmddyy10.), 'g');
run;
 
%put &dt;
Super User
Super User
Posts: 7,083

Re: how do i create a macro variable of todays date like this 20170424

What format you have attached to the variable doesn't matter, in fact you do not even need to create a variable. You want to use PUT() function to convert a value to a character string not the INPUT() function. The INPUT() function is for converting character strings into stored values.  It is easy to remember if you think of the PUT and INPUT statements that are used to write and read characters from text files.

 

You can use the DATE() function (or its alias today()) to get the date when the statement runs.

 

data _null_;
   call symputx('dt',put(date(),yymmddn8.));
run;

 

or you can use the automatic macro variable SYSDATE9 to get the date when the program started (which might be yesterday or even earlier if you have a long runnning job).

 

data _null_;
   call symputx('dt',put("&sysdate9"d,yymmddn8.));
run;

 

 

Contributor
Posts: 46

Re: how do i create a macro variable of todays date like this 20170424

thanks, i used your first one.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 3197 views
  • 0 likes
  • 4 in conversation