Sentry Page Protection
Handling Date Values [3-7]
Additional Date Informats In the previous section, we saw an example of how to use the (date9.) informat to read data into SAS.
In fact, there are a number of date informats in SAS that allow you to read different types of date values into the data set. Below are some examples: Let's look at an example: data datelist; input date : mmddyy10. time : time5. ; format date mmddyy10. time time5.; datalines; 07-14-1983 5:00 05-21-1986 9:00 ; run; The data step in this example reads a date column and a time column into a data set. The date values are formatted as 'MM-DD-YYYY' and the time values are formatted as 'HH:MM'. These values can be read into a SAS data set using the (mmddyy10.) and (time5.) informats. The date and time values are read into the data set and are displayed properly as readable date and time values: Additional Date Formats There are also other date formats available that allow you to display the date values differently. Below are some examples: Let's look at the data step below: data dateformats; input date1 : mmddyy10. date2 : mmddyy10. ; format date1 weekdate. date2 worddate.; datalines; 07-14-1983 07-14-1983 05-21-1986 05-21-1986 ; run; The FORMAT statement assigns the (weekdate.) and (worddate.) format to the DATE1 and DATE2 variables, respectively. The two date columns are now formatted accordingly. Exercise
The code below reads the student ID into SAS along with the student's date of graduation ceremony. Assign an appropriate informat to format the variables so that the values are read into SAS properly. The date of graduation ceremony should be displayed in the format of 'Sunday, May 19, 2019'. data ceremony; input studentID ceremonydate; datalines; STU1001 19-05-2019 STU1002 20-05-2019 STU1003 21-05-2019 STU1004 22-05-2019 ; run; Need some help?
HINT: SOLUTION: data ceremony;
Fill out my online form.
|