Displaying Date and Time Values with Formats

SAS stores date and time values as numeric variables. Formats should be applied to the data so that meaningful date and time values are displayed in reports.

The WEEKDATEw. Format

Use the WEEKDATEw. format to write date values in a format that displays the day of the week, month, day, and year.
Syntax, WEEKDATEw. format:
WEEKDATEw.
The WEEKDATEw. format writes date values in the form day-of-week, month-name dd, yy (or yyyy).
  • dd is an integer between 01 and 31, representing the day.
  • yy or yyyy is an integer that represents the year.
Note: If the w value is too small to write the complete day of the week and month, SAS abbreviates as needed.
proc print data=perm.aprbills; 
   format datein dateout weekdate17.; 
run;
Figure 19.7 PROC PRINT Output for the above Example
PROC PRINT output for the above example.
You can vary the results by changing the w value in the format.
FORMAT Statement
Result
format datein weekdate3.;
Mon
format datein weekdate6.;
Monday
format datein weekdate17.;
Mon, Apr 5, 2009
format datein weekdate21.;
Monday, April 5, 2009

The WORDDATEw. Format

The WORDDATEw. format is similar to the WEEKDATEw. format, but it does not display the day of the week or the two-digit year values.
Syntax, WORDDATEw. format:
WORDDATEw.
The WORDDATEw. format writes date values in the form month-name dd, yyyy.
  • dd is an integer between 01 and 31, representing the day.
  • yyyy is an integer that represents the year.
Note: If the w value is too small to write the complete month, SAS abbreviates as needed.
proc print data=perm.aprbills; 
   format datein dateout worddate12.; 
run;
Figure 19.8 PROC PRINT Output for the Example
PROC PRINT output for the above example.
You can vary the results by changing the w value in the format.
Table 19.8 FORMAT Statements and Corresponding Results
FORMAT Statement
Result
format datein worddate3.;
Apr
format datein worddate5.;
April
format datein worddate14.;
April 15, 1999
You can permanently assign a format to variable values by including a FORMAT statement in the DATA step.
options yearcutoff=1926; 
data work.aprbills; 
   infile aprdata; 
   input LastName $8. @10 DateIn mmddyy8. +1 DateOut 
      mmddyy8. RoomRate 6. @34 EquipCost 6.; 
   Days=dateout-datein+1; 
   RoomCharge=days*roomrate; 
   Total=roomcharge+equipcost; 
   format datein dateout worddate12.; 
run; 
proc print data=work.aprbills; 
run;
Last updated: January 10, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.70.185