10-11-2015 12:40 PM
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:
10(month) to SYSMONTH
11(date) to SYSDATE and
2015(year) to SYSYEAR.
Help much appreciated..
10-11-2015 02:22 PM - edited 10-11-2015 02:22 PM
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,-);