BookmarkSubscribeRSS Feed
Wheelawake
Calcite | Level 5

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!



2 REPLIES 2
ballardw
Super User

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.

Fugue
Quartz | Level 8

specify a datetime or similiar format, eg:

input Finished_On : MDYAMPM20. ;

format Finished_On datetime20.;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 819 views
  • 0 likes
  • 3 in conversation