Creating SAS Data Sets from Raw Data Files (Data Delimited)

Reply
New Contributor
Posts: 2

Creating SAS Data Sets from Raw Data Files (Data Delimited)

Hello,

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:


options validvarname=any;

data work.test;
infile 'C:\mypath\file.csv' dlm=',';
Module='Test Name';
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;
run;

proc print data=work.test;
run;

Output:

Test Name         John Doe         100%           1690411140   (want this to be formatted as a date)

Thank you so much for your help!



Super User
Posts: 11,343

Re: Creating SAS Data Sets from Raw Data Files (Data Delimited)

Posted in reply to Wheelawake

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.

Super Contributor
Posts: 307

Re: Creating SAS Data Sets from Raw Data Files (Data Delimited)

Posted in reply to Wheelawake

specify a datetime or similiar format, eg:

input Finished_On : MDYAMPM20. ;

format Finished_On datetime20.;

Ask a Question
Discussion stats
  • 2 replies
  • 158 views
  • 0 likes
  • 3 in conversation