SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Search||next

Transforming Data with SAS Functions
Manipulating SAS Date Values with Functions

 
Now let's use the MONTH function to complete the following task.

Suppose you need to create a subset of the data set Hrd.Temp that contains information about all temporary employees hired during November. Hrd.Temp contains the dates that employees began work with the company and their ending dates, but there is no month variable.


SAS Data Set Hrd.Temp
City State Zip Phone BeginDate EndDate PayRate Days Hours
CARY NC 27513 6224549 14567 14621 10 11 88
CARY NC 27513 6223251 14524 14565 8 25 200
CHAPEL HILL NC 27514 9974749 14570 14608 40 26 208
RALEIGH NC 27612 6970450 14516 14527 15 10 80


To determine in which month employees were hired, you can apply the MONTH function to the variable that contains the employee start date, BeginDate. You write the MONTH function as
     month(begindate)

Then, to create the new data set, you include this function in a subsetting IF statement within a DATA step. This subsetting IF statement specifies that only observations in which the MONTH function extracts a value of 11 (for November) are placed in the new data set.

     data hrd.tempnov;
        set hrd.temp;
        if month(begindate)=11;
     run;

Finally, you add a PROC PRINT step to the program so you can view the new data set. Notice that the PROC PRINT step includes a FORMAT statement to display the variables BeginDate and EndDate with the DATE9. format.

     data hrd.tempnov;
        set hrd.temp;
        if month(begindate)=11;
     proc print data=hrd.tempnov;
        format begindate enddate date9.;
     run;

Here is a portion of the PROC PRINT output that is created by your program. Notice that the new data set contains information only about those employees who were hired in November.


City State Zip Phone BeginDate EndDate Pay
Rate
Days Hours
CARY NC 27513 6224549 19NOV1999 12JAN2000 10 11 88
CHAPEL HILL NC 27514 9974749 22NOV1999 30DEC1999 40 26 208
DURHAM NC 27713 3633618 02NOV1999 13NOV1999 12 9 72
CARRBORO NC 27510 9976732 16NOV1999 04JAN2000 15 7 64



|next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement