Hi everyone,
Please help me with this query. I want to convert this date 20DEC2019:12:49:00.000 to 20DEC2019.
Why did you use PUT() to convert it to character if you didn't want a character variable?
Might help to use more descriptive names for the variables.
data test;
set hello;
AppDate1 = datepart(AppDate);
format appdate1 date9.;
rename appdate=AppDatetime appdate1=AppDate ;
run;
Use the DATEPART() function and apply the DATE9. format
The first one looks like a DATETIME value, not a DATE value.
SAS stores DATETIME values as number of seconds since 1960 and DATE values as number of days since 1960.
To convert the number of seconds into number of days you can use the DATEPART() function. You will then need to use a date type format, like the DATE format that display in the style you showed, with the new value.
If you just want to change how the value is displayed you can just change the FORMAT used to display the value without changing the value that is stored. The DTDATE format will display datetime values in the style that the DATE format displays date values.
Why did you use PUT() to convert it to character if you didn't want a character variable?
Might help to use more descriptive names for the variables.
data test;
set hello;
AppDate1 = datepart(AppDate);
format appdate1 date9.;
rename appdate=AppDatetime appdate1=AppDate ;
run;
The PUT function takes stuff (character or numeric), and converts it to character according to the used format.
You do not want it here. Just use the DATEPART function and a FORMAT statement:
data test;
set hello;
AppDate1 = datepart(AppDate);
format Appdate1 date9.;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.