BookmarkSubscribeRSS Feed
steve_citi
Calcite | Level 5
Kudoes to anyone who can figure out why this is not working!! (I can't)

I am converting a sas date to a sas datetime. Simple enough, right?

This works:

data newtreat2;
set newtreatments;
format work_datetime datetime23.3;
work_datetime=dhms(workout_date,0,0,0);
run;


BUT.....when I use almost the same code in a merge step, it does not work. In fact, the answer it does give is very interesting, though wrong.

(I am NOT showing the whole merge step, way too complicated)

THEN DO;
ADF_USER_FIELD_5=initial;
work_datetime=dhms(workout_date,0,0,0);
ADF_USER_DATE_5 =work_datetime;
END;

The value, adf_user_field_5 comes back as a certain number of hours minutes and seconds in January 1st 1960.....if you figure out the total number of seconds that those hours minutes and seconds represent is is EQUAL to the sas date value of workout_date.

Why?
4 REPLIES 4
Doc_Duke
Rhodochrosite | Level 12
Your code looks OK. Suspect your problem is elsewhere. Put a put statement at the beginning an end of the DO group for diagnostics. You may need to simply the program to the point that you can show it all.
ArtC
Rhodochrosite | Level 12
Double check to make sure that the length of the datetime variable has not been shortened.
sfsdtegsdsdgdffhgfh
Fluorite | Level 6
can you put the example of corresponding datetime value after using the formula. Message was edited by: sastech
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
As was suggested, adding a PUT (or PUTLOG _ALL_; with SAS 9) will help but then also if the SAS LENGTH for the DATETIME (numeric variable, time in seconds since 1/1/1960 - minimum length of 7, better to be 8 with STORE_CLOCK values) variable is truncated, you will not see evidence of a problem until a subsequent PROC or DATA step, where the variable is referenced.

Another self-initiated desk-checking technique by the OP would be to perform a PROC CONTENTS on the file immediately after the assignment "step", to verify/inspect the SAS NUMERIC variable "length" attribute for the DATETIME variable.

Also, consider that declaring a SAS FORMAT is not the equivalent of declaring a SAS LENGTH (either as a statement or as a keyword for the ATTRIB statement) -- your SAS variable may still be truncated without warning.

Scott Barry
SBBWorks, Inc.

Encouraged SAS system/programming reading:

SAS Language Reference: Concepts, About SAS Date, Time, and Datetime Values
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002200738.htm


SAS Language Reference: Concepts, Numeric Precision in SAS Software
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000695157.htm


Recommended Google advanced search argument, this topic/post:

datetime numeric variable truncated site:sas.com

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 926 views
  • 0 likes
  • 5 in conversation