08-23-2013 03:39 PM
I am trying to read raw data into a sas data set and I keep getting numbers like 1690411140. I am having trouble formatting this into a normal date, such as 8/23/2013...
Any help would be much appreciated! I am new to SAS and this one little thing is holding me up!
Example of raw data file (fake data)
Student,Points Awarded,Points Available,%,Grading Status,Finished On,Version
John Doe,10,10,100%,Graded,7/25/2015 10:39 PM,4
Code I wrote:
infile 'C:\mypath\file.csv' dlm=',';
length Student $ 20;
input Student $ Points_Awarded Points_Available '%'n percent4. Grading_Status $ Finished_On : MDYAMPM20. Version $;
format '%'n percent6. Finished_On month9.;
drop Grading_Status Points_Awarded Points_Available Version;
if Student='Student' then delete;
proc print data=work.test;
Test Name John Doe 100% 1690411140 (want this to be formatted as a date)
Thank you so much for your help!
08-23-2013 03:48 PM
Your Finished_On variable is a datetime value. There are a limited number of formats that will display the date directly from datetime, DTDATE9. probably is closest. You could either assign the format permanently by adding
format Finished_On DTdate9. ; in the data step or the same syntax in the proc print for a temporary association.
If you want more control over appearance you may want to create a date only variable such as:
Date_finished = datepart(Finished_on);
format Date_Finished mmddyy10. ;
Or pick one of the many DATE related formats.