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

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1270 views
  • 1 like
  • 4 in conversation