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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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
  • 5 replies
  • 1388 views
  • 3 likes
  • 4 in conversation