- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 07-28-2008 12:06 PM
(5148 views)
Hi
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
tday=28072008
yyyy=2008
yyyy2=2008
mm=07
mm2=06
But if for eg todays date was 15/01/2009 is where i get my problem!
Please help
Thanks
Spud
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
tday=28072008
yyyy=2008
yyyy2=2008
mm=07
mm2=06
But if for eg todays date was 15/01/2009 is where i get my problem!
Please help
Thanks
Spud
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Spud.
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.
[pre]
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.)) ;
RUN ;
%PUT _USER_ ;
[/pre]
Regards
Olivier
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.
[pre]
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.)) ;
RUN ;
%PUT _USER_ ;
[/pre]
Regards
Olivier
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Olivier
It worked a treat!
It worked a treat!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Last question if i want a 3 letter month what would be the format?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Scott Barry
SBBWorks, Inc.
___________________
SAS 913 DOC - MONNAME format (with examples!):
http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000201049.htm
SAS 913 DOC - FORMATS chapter in SAS Language Reference: Dictionary
http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000309859.htm
Scott Barry
SBBWorks, Inc.
___________________
SAS 913 DOC - MONNAME format (with examples!):
http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000201049.htm
SAS 913 DOC - FORMATS chapter in SAS Language Reference: Dictionary
http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000309859.htm