I have a variable whose format is DATETIME. . But after
format time yymmdd10. ;The values of variable become ******. I have tried quarter=input(time, yyddmm10.) and quarter=put(time,yymmdd10.). But they all become *****.
Before:
After
Alternatively, you may want to extract the dates from your datetime values by means of the DATEPART function and then assign the date format of your choice to the resulting SAS date values:
data want;
set have;
date=datepart(time);
format date yymmdd10.;
run;
Background:
Variables with date, time or datetime formats are ordinary numeric variables, i.e., they contain numbers.
What kind of numbers?
Date, time and datetime formats interpret these numbers accordingly in order to display the values in a human readable form.
So, when you (inappropriately) apply the date format YYMMDD10. to your datetime variable TIME, SAS tries to interpret values like 1238585400 (a number of seconds after 1 Jan 1960, 00:00) as a number of days after 1 Jan 1960. The result, a date about 3 million years (!) from now, exceeds the range of admissible SAS date values and is therefore displayed as ********** by format YYMMDD10.
Your data in variable TIME is a date-time value, not a date value.
Therefore, you have to use a date-time format, not a date format.
For example:
format time datetime7.;
Alternatively, you may want to extract the dates from your datetime values by means of the DATEPART function and then assign the date format of your choice to the resulting SAS date values:
data want;
set have;
date=datepart(time);
format date yymmdd10.;
run;
Background:
Variables with date, time or datetime formats are ordinary numeric variables, i.e., they contain numbers.
What kind of numbers?
Date, time and datetime formats interpret these numbers accordingly in order to display the values in a human readable form.
So, when you (inappropriately) apply the date format YYMMDD10. to your datetime variable TIME, SAS tries to interpret values like 1238585400 (a number of seconds after 1 Jan 1960, 00:00) as a number of days after 1 Jan 1960. The result, a date about 3 million years (!) from now, exceeds the range of admissible SAS date values and is therefore displayed as ********** by format YYMMDD10.
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.