Example: Using Dates and Times in Calculations

Suppose you work in the billing department of a small community hospital. In this example, you create a new SAS data set from the input data file that is referenced by the fileref Aprbills. A portion of the data file below shows the following patient data:
  • last name
  • date checked in
  • date checked out
  • daily room rate
  • equipment cost
Output 13.4 Unformatted Cert.AprBills Data Set
Cert.AprBills Data Set
data work.aprhospitalbills;
  set cert.aprbills;
  Days=dateout-datein+1;                  /*#1*/
  RoomCharge=days*roomrate;               /*#2*/
  Total=roomcharge+equipcost;             /*#3*/
run;
proc print data=work.aprhospitalbills;
  format DateIn DateOut mmddyy8.;         /*#4*/
run;
1 Create a new variable named Days and calculate how many days each patient was hospitalized. Since DateIn and DateOut are numeric variables, you can simply subtract to find the difference. However, the dates should be inclusive because patients are charged for both the first and last days. Therefore, you must add 1 to the difference.
2 Create a new variable named RoomCharge by multiplying the number of Days by the RoomRate value.
3 To calculate the total cost for each patient, create a variable named Total whose value is the sum of RoomCharge and EquipCost.
4 Use the FORMAT statement to associate the format MMDDYY8. to the DateIn and DateOut variable.
Output 13.5 PROC PRINT Output for Work.AprHospitalBills
PROC PRINT Work.AprHospitalBills
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
3.22.186.127