In: Computer Science
Using the following lines of data, create a temporary SAS data set called ThreeDates. Each line of data contains three dates, the first two in the form mm/dd/yyyy descenders and the last in the form ddmmmyyyy. Name the three date variables Date1, Date2, and Date3. Format all three using the MMDDYY10. format. Include in your data set the number of years from Date1 to Date2 (Year12) and the number of years from Date2 to Date3 (Year23). Round these values to the nearest year. Here are the lines of data (note that the columns do not line up):
01/03/1950 01/03/1960 03Jan1970
05/15/2000 05/15/2002 15May2003
10/10/1998 11/12/2000 25Dec2005
The Data Sets are called temporary Data Set if they are used by the SAS program and then discarded after the session is run.
But if it is stored permanently for future use then it is called a permanent Data set. All permanent Data Sets are stored under a specific library.
FUNCTIONS that are we going to use in this as mentioned in 1,2, and 3 points:-
1) Using set function ,we will access the values from the above dataset.
2) Using yrdif function we'll calculate the difference between date1, date2 and date3 variables.
3 Using round command for rounding them(values) along with yrdif function.
NOTE :- Returns the difference in years between two date. YRDIF function has been used to compute ages in this way: age = INT(YRDIF(birth-date, ending-date,'ACTUAL'));
LETS START:- Here I have used seperate data set for loading the values.
data a15009.three;
input @1 Date1 mmddyy10.
@12 Date2 mmddyy10.
@23 Date3 date9. ;
format Date1 Date2 Date3 mmddyy10.;
datalines;
01/03/1950 01/03/1960 03Jan1970
05/15/2000 05/15/2002 15May2003
10/10/1998 11/12/2000 25Dec2005
;
data a15009.threedates;
set a15009..three;
year12 = round(yrdif(Date1,Date2, 'Actual'));
year23 = round(yrdif(Date2,Date3, 'Actual'));
run;
proc print data = threedates;
run;
proc print data = a15009.threedates; run;
Obs Date1 Date2 Date3 year12 year23
1 01/03/1950 01/03/1960 03Jan1970 10 10
2 05/15/2000 05/15/2002 15May2003 2 1
3 10/10/1998 11/12/2000 25Dec2005 2 5