BookmarkSubscribeRSS Feed
statadm
Fluorite | Level 6
I'm using the following code and never had a problem before, but the minutes are not always correct.

the original time variable data looks like "2030":

delhr=SUBSTR(Del_time, 1,2);
delmin=SUBSTR(Del_time, 3,2);
del_time= trim(delhr)||':'||trim(delmin);


format DELTIME time5.;
DELTIME=input(del_time,time5.); Message was edited by: statadm
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
I'd say that you're going to need to demonstrate the "symptom condition" by pasting some of a SAS log, where the time-variable assigned is incorrect as you have explained. You can use a PUT statement in your DATA step, however since precision is a consideration (the LENGTH attribute of your SAS numeric variable), you will need to also demonstrate the problem likely with a follow-on PROC PRINT or another DATA step where you input the same, just-created SAS file, and then do another PUT. SAS stores these numeric variables in floating-point until saved to the SAS library -- that's why doing a PUT in the "input processing" DATA step is not going to be useful to debug -- of course unless you have some true INPUT logic or input-data problems.

Scott Barry
statadm
Fluorite | Level 6
After taking a break and coming back to it, I realized it was just a matter of SAS not liking the use of the same name for the variable. It works correctly if I rename the variable to del_time1 instead of overwriting the character variable with numeric data.

Thanks for your suggestion.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
From what you posted, there are different names for the two SAS CHARACTER and NUMERIC variables. SAS would not permit you to interchange one for the other without some warning or error diagnostic.

Scott
statadm
Fluorite | Level 6
I changed the original program:

delhr=SUBSTR(Del_time, 1,2);
delmin=SUBSTR(Del_time, 3,2);
del_time= trim(delhr)||':'||trim(delmin);


format DELTIME time5.;
DELTIME=input(del_time,time5.);

To read as follows:

delhr=SUBSTR(Del_time, 1,2);
delmin=SUBSTR(Del_time, 3,2);
del_time1= trim(delhr)||':'||trim(delmin);


format DELTIME time5.;
DELTIME=input(del_time1,time5.);

I'm sorry, I mean that it didn't like me using the same variable name for the original variable and the new character variable with the ":". Once I changed this, it worked fine.
Doc_Duke
Rhodochrosite | Level 12
Reading the thread, I have a strong suspicion that the underlying cause of the problem is not that SAS doesn't like reusing a variable name (that's fine), but that the original del_time was character length=4 and the assignment truncated the minutes in the assignment statement

del_time= trim(delhr)||':'||trim(delmin);

when the original value was "1000" or greater.

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