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!
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.
See https://marc.info/?l=sas-l&m=116624449238415&w=2
@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.;
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.
@ballardw Thank you for taking the time to solve my problem!
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
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.
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.
Ready to level-up your skills? Choose your own adventure.