Hi all, I have a list of Datetime values (e.g. 02JAN1970:01:00:02) that I want to convert into numerical having the following format: 19700102
I have wrote the following code, but it ends up showing a list of dots instead of the actual dates.
data table_2; set table_1; day_p = datepart(day_p); format day_p yymmddn8.; run; data table_3; set table_2; day_p = input(put(input(day_p,date9.),yymmddn8.),8.); format day_p 8.; run;
May anyone help me in solving this issue?
Thank you in advance
You have an INPUT() too many:
data want;
dt = "02JAN1970:01:00:02"dt;
day_p = datepart(dt);
day_n = input(put(day_p,yymmddn8.),8.);
format
dt datetime19.
day_p yymmddd10.
day_n 8.
;
run;
Be advised that the result is not useful for anything. You can't use it in calculations, cannot display it nicely, and can't use the gazillion goodies that SAS provides for handling dates. It needs more bytes than a SAS date (which can be stored with 4) on top.
You have an INPUT() too many:
data want;
dt = "02JAN1970:01:00:02"dt;
day_p = datepart(dt);
day_n = input(put(day_p,yymmddn8.),8.);
format
dt datetime19.
day_p yymmddd10.
day_n 8.
;
run;
Be advised that the result is not useful for anything. You can't use it in calculations, cannot display it nicely, and can't use the gazillion goodies that SAS provides for handling dates. It needs more bytes than a SAS date (which can be stored with 4) on top.
Absolutely. Anything that is a date, time or datetime value should be stored as such in SAS. Even things that show only periods (year/month) should be stored as a date (1st of month) with a format that shows year/month only, like yymmd7. Because then you can still use functions to calculate intervals etc.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.