BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kilasuelika
Fluorite | Level 6

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:

2018-06-24_18-36-36.jpg2018-06-24_18-37-08.jpg

 

 

After

2018-06-24_18-37-48.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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?

  • numbers of days after 1 January 1960 in the case of date values (e.g. 14335 for 1 April 1999)
  • numbers of seconds after midnight (00:00) in the case of time values (e.g. 41400 for 11:30 AM)
  • numbers of seconds after 1 January 1960, 00:00 in the case of datetime values (e.g. 1238585400 for 1 April 1999, 11:30 AM).

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.

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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.;

 

--
Paige Miller
FreelanceReinh
Jade | Level 19

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?

  • numbers of days after 1 January 1960 in the case of date values (e.g. 14335 for 1 April 1999)
  • numbers of seconds after midnight (00:00) in the case of time values (e.g. 41400 for 11:30 AM)
  • numbers of seconds after 1 January 1960, 00:00 in the case of datetime values (e.g. 1238585400 for 1 April 1999, 11:30 AM).

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 449 views
  • 5 likes
  • 3 in conversation