As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Macro Loops with Dates

From sasCommunity
Jump to: navigation, search

Writing Macro Loops with Dates from Then to Now

Overview

Program

 /*    name: date-mvars
description: provide list of system mvars with dates
purpose    : show how to convert dates to integers
sas.help: About SAS Date, Time, and Datetime Values
          Dictionary of Functions and CALL Routines
          Working with Dates in the SAS System: Comparing Durations and SAS Date Values
          Working with Dates in the SAS System: Understanding How SAS Handles Dates
 
other formats with year2:
%put today: &today %sysfunc(putn(&today,date7.));
%put today: &today %sysfunc(putn(&today,mmddyy10.));
*******/
%put sysdate: &Sysdate.;
%put sysdate9: &Sysdate9.;
 
%let today = %sysevalf('10JAN2013'd);
%let today = %sysevalf('10Feb2013'd);
%let today = %sysevalf('21Dec2012'd);
*let today = %sysevalf("&Sysdate9."d);
*let today = %sysfunc(today()) ;
*let today = %sysfunc(date()) ;
 
%put today: &today %sysfunc(putn(&today,date9.));
%put today: &today %sysfunc(putn(&today,mmddyy10.));
%put today: &today %sysfunc(putn(&today,worddate18.));
%put today: &today %sysfunc(putn(&today,weekdate29.));
 
*parts:;
%put day/month: &today %sysfunc(day(&today));
%put month: &today %sysfunc(month(&today));
%put year: &today %sysfunc(year(&today));
 
%put week/year: &today %sysfunc(week(&today,u));
%put week/year: &today %sysfunc(week(&today,v));
%put week/year: &today %sysfunc(week(&today,w));
 
%put day/year: &today %substr(%sysfunc(juldate7(&today)),5,3);

log:

14         %put sysdate9: &Sysdate9.;
sysdate9: 15JAN2013
15         
18         %let today = %sysevalf('21Dec2012'd);

23         %put today: &today %sysfunc(putn(&today,date9.));
today: 19348 21DEC2012
24         %put today: &today %sysfunc(putn(&today,mmddyy10.));
today: 19348 12/21/2012
25         %put today: &today %sysfunc(putn(&today,worddate18.));
today: 19348  December 21, 2012
26         %put today: &today %sysfunc(putn(&today,weekdate29.));
today: 19348     Friday, December 21, 2012
27         
28         *parts:;
29         %put day/month: &today %sysfunc(day(&today));
day/month: 19348 21
30         %put month: &today %sysfunc(month(&today));
month: 19348 12
31         %put year: &today %sysfunc(year(&today));
year: 19348 2012
32         
33         %put week/year: &today %sysfunc(week(&today,u));
week/year: 19348 51
34         %put week/year: &today %sysfunc(week(&today,v));
week/year: 19348 51
35         %put week/year: &today %sysfunc(week(&today,w));
week/year: 19348 51
36         
37         %put day/year: &today %substr(%sysfunc(juldate7(&today)),5,3);
day/year: 19348 356

References

--Ronald_J._Fehd macro.maven == the radical programmer 18:43, 15 January 2013 (EST)