Displaying Date and Time Values with Formats

SAS stores date and time values as numeric values. You apply SAS formats 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=work.aprhospitalbills; 
   format datein dateout weekdate17.; 
run;
Output 13.6 PROC PRINT Output for Work.AprHospitalBills
PROC PRINT Work.AprHospitalBills
You can vary the results by changing the w value in the format.
FORMAT Statement
Result
format datein weekdate3.;
Tue
format datein weekdate10.;
Tuesday
format datein weekdate17.;
Tue, Apr 3, 2018
format datein weekdate31.;
Tuesday, Apr 3, 2018

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=work.aprhospitalbills; 
   format datein dateout worddate12.; 
run;
Output 13.7 PROC PRINT Output for Work.AprHospitalBills
PROC PRINT Work.AprHospitalBills WordDate12.
You can vary the results by changing the w value in the format.
Table 13.6 FORMAT Statements and Corresponding Results
FORMAT Statement
Result
format datein worddate3.;
Apr
format datein worddate9.;
April
format datein worddate14.;
April 3, 2018
You can permanently assign a format to variable values by including a FORMAT statement in the DATA step.
data work.aprhospitalbills;
  set cert.aprbills;
  Days=dateout-datein+1;
  RoomCharge=days*roomrate;
  Total=roomcharge+equipcost;
  format datein dateout worddate12.;
run;
proc print data=work.aprhospitalbills;
run;
Last updated: August 23, 2018
..................Content has been hidden....................

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