Im trying to have 5 macro variables,
%tday which contains todays full date
%yyyy which contains todays year as 4 digits
%yyyy2 which contains last months year as 4 digits
%mm which contains todays month as 2 digits
%mm2 which contains last months month as 2 digits.
for eg todays(28/07/2008) would be
But if for eg todays date was 15/01/2009 is where i get my problem!
Instead of hard coding today's date and substracting from it, you can let SAS do computations. You can do that with the %SYSFUNC macro function, but it becomes a little boring when you have more than you function to access at a time. So what I think is the most simple solution is to create dates in a Data step, and then record their values, using the Call Symput routine. You can use functions as INTNX to build last month's date, and formats to extract parts of the information.
DATA _NULL_ ;
today = TODAY() ;
lastMonth = INTNX("MONTH", today, -1) ;
CALL SYMPUT("tday", PUT(today, DDMMYYN8.)) ;
CALL SYMPUT("yyyy", PUT(today, YEAR4.)) ;
CALL SYMPUT("yyyy2", PUT(lastMonth, YEAR4.)) ;
CALL SYMPUT("mm", PUT(MONTH(today),Z2.)) ;
CALL SYMPUT("mm2", PUT(MONTH(lastMonth),Z2.)) ;
%PUT _USER_ ;
You have a choice, either use the SAS FORMAT MONNAME or WORDDATE with the trailing length specification to truncate the displayed value. If you need the string in uppercase (as I do often), assign a SAS character variable and use the UPCASE function and the PUT function with the desired format.