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

Hi all,

 

  My hospital length of stays were in excel as '55:02:00' which are in hours and there must have previously been some character code in the column, because when I imported to SAS it changed to $31. and looks like '2.293055555555555556' except it's now in character. Any ideas how to convert it this into days (numeric?) and round up or down from the 10ths place.

Data have;

HLOS

55:02:00

203:46:00

192:42:00

 

data want;

HLOS (days)

2

8

1 ACCEPTED SOLUTION

Accepted Solutions
mklangley
Lapis Lazuli | Level 10

@stancemcgraw  Since you already have the number of days in character strings, give this a try.

data have;
    input hlos $31.;
    datalines;
    2.293055555555555556
    8.490277777777777
    8.0291667
;
run;

data want;
    set have;
    hlos_numeric = round(input(hlos, 12.4), 1);
run;

(Also, I believe your second example would round off to 8 days, not 9.)

View solution in original post

3 REPLIES 3
Reeza
Super User
How did you import your data? Can you fix it in that step?
PaigeMiller
Diamond | Level 26

Since you already have the values as '2.293055555555555556', just take this character string and convert it into days

 

days=input(hlos,7.0);

If you want to round off, instead of truncate (which is what the above code will do), then you can modify the code properly.

--
Paige Miller
mklangley
Lapis Lazuli | Level 10

@stancemcgraw  Since you already have the number of days in character strings, give this a try.

data have;
    input hlos $31.;
    datalines;
    2.293055555555555556
    8.490277777777777
    8.0291667
;
run;

data want;
    set have;
    hlos_numeric = round(input(hlos, 12.4), 1);
run;

(Also, I believe your second example would round off to 8 days, not 9.)

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 581 views
  • 1 like
  • 4 in conversation