Read system date and move it into a new field

Reply
Contributor
Posts: 20

Read system date and move it into a new field

Hi ,

 

In my requirement, I need to read system date and once done, I need to move date to one field, month to other field and year to another field. Please tell me how can I achieve this?

 

For example: If the system date is 10/11/2015(mmddyyyy) then I need to read this date and move as follows:

 

CURRDATE=10/11/2015

10(month) to SYSMONTH

11(date) to SYSDATE and

2015(year) to SYSYEAR.

 

Help much appreciated.. 

Super User
Super User
Posts: 6,845

Re: Read system date and move it into a new field

[ Edited ]

I have renamed one of your variables to SYSDOM (Day of Month) from SYSDATE because the macro variables SYSDATE and SYSDAY already exist and are populated with the date and day of the week when the current SAS session started.

 

In a data step:

 

CURRDATE=date();
SYSMONTH=month(currdate);
SYSDOM=day(currdate);
SYSYEAR=year(currdate);

In macro code:

%let CURRDATE=%sysfunc(date());
%let SYSMONTH=%sysfunc(month(&currdate));
%let SYSDOM=%sysfunc(day(&currdate));
%let SYSYEAR=%sysfunc(year(&currdate));

Note that this will make &CURRDATE be the number of days since 1/1/1960.  If you want it formatted then you can add an optional format to the %SYSFUNC(DATE()) function call, but then it will be harder to use in the other calls.

For example if you wanted it formatted as YYYY-MM-DD then you could use:

 

%let CURRDATE=%sysfunc(date(),yymmddd10);
%let SYSMONTH=%scan(&currdate,2,-);
%let SYSDOM=%scan(&currdate,3,-);
%let SYSYEAR=%scan(&currdate,1,-);

 

Ask a Question
Discussion stats
  • 1 reply
  • 200 views
  • 0 likes
  • 2 in conversation