BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
vanja
Obsidian | Level 7

I have imported SPSS files (.sav) into SAS Viya via proc import. But the date variables are not converted into SAS dates. After some investigation I found that the value I have got is a numeric value representing the number of seconds since October 14 year 1582. For example the number 13759718400 represents 24-Oct-2018.

 

Is there a SAS function to translate this numeric value to a SAS date variable? Or has someone here invented the code needed for this conversion?

 

I still have the option to save my spss file into a sas dataset and then import it.  I have checked that the date variables will be ok.  But now I'm curious to know if there is a very simple solution to my problem. Thanks in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Easy to convert the value to a SAS datetime value add the result of dhms('14OCT1582'd,0,0,0)

 

data example;
   x=13759718400;
   offset = dhms('14OCT1582'd,0,0,0);
   SASDatetime = x+offset;
   format SASDatetime datetime20.;
   datevalue=datepart(x);
   format datevalue date9.;
run;

If you want a DATE value then extract using the DATEPART function.

View solution in original post

5 REPLIES 5
vanja
Obsidian | Level 7

@PaigeMiller Thank you, the solution you provided link to also worked.

days = datespss/86400;
datesas = date() - ( date() - MDY(10,14,1582) - days );
format datesas date9.;

 

ballardw
Super User

Easy to convert the value to a SAS datetime value add the result of dhms('14OCT1582'd,0,0,0)

 

data example;
   x=13759718400;
   offset = dhms('14OCT1582'd,0,0,0);
   SASDatetime = x+offset;
   format SASDatetime datetime20.;
   datevalue=datepart(x);
   format datevalue date9.;
run;

If you want a DATE value then extract using the DATEPART function.

vanja
Obsidian | Level 7

@ballardw Thank you for taking the time to solve my problem!

Tom
Super User Tom
Super User

Actually that value represents the DATETIME value 24OCT2018:00:00:00.  To convert the result to a DATE value use the DATEPART() function.

 

Just add '14OCT1582:00:00'dt to it to convert it to a SAS datetime value.

1    data test;
2      spss_dt = 13759718400;
3      sas_dt = spss_dt + '14OCT1582:00:00'dt ;
4      dt = sas_dt;
5      date = datepart(dt);
6      format spss_dt sas_dt comma15. dt datetime19. date date9.;
7      put (_all_) (=/);
8    run;


spss_dt=13,759,718,400
sas_dt=1,855,958,400
dt=24OCT2018:00:00:00
date=24OCT2018
NOTE: The data set WORK.TEST has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 488 views
  • 3 likes
  • 4 in conversation