Using Dates in Calculations

Sorting Dates

Because SAS date values are numeric variables, you can sort them and use them in calculations. The following example uses the data set MYLIB.TOURDATES to extract other information about the Tradewinds Travel data.
To help determine how frequently tours are scheduled, you can print a report with the tours listed in chronological order. The first step is to specify the following BY statement in a PROC SORT step to tell SAS to arrange the observations in ascending order of the date variable DepartureDate:
by DepartureDate;
By using a VAR statement in the following PROC PRINT step, you can list the departure date as the first column in the report:
proc sort data=mylib.fmttourdate out=sortdate;
   by DepartureDate; ...

Get Step-by-Step Programming with Base SAS 9.4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.