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

Hello-,

 

I have a date format below. I want to drop the last four digit ie 1950 and 1421 from the date and subtract 2/10/2017-2/9/2017

  data AA;

input  ADT_IN  ADT_OUT;

   
2/9/2017 1950 2/10/2017 1421
2/8/2017 1750 2/10/2017 1240
2/7/2017 1143 2/9/2017 1250
2/8/2017 1256 2/11/2017 0042
   
   
   
   
   
2/8/2017 1357 2/9/2017 1339
2/8/2017 1236 2/10/2017 1809
   
2/8/2017 1236 2/10/2017 1809

;

 

 

 

How do I perform length of stay (LOS) using the above data.  LOS= out-in above

1 ACCEPTED SOLUTION

Accepted Solutions
desireatem
Pyrite | Level 9

works

 

data D_HPT;
set D_HPT;
los=input(scan(ADT_out,1," "),ddmmyy10.)-input(scan(ADT_IN,1," "),ddmmyy10.)/365;
run;

View solution in original post

8 REPLIES 8
Reeza
Super User

SCAN to separate components

INPUT to convert character to date

 

desireatem
Pyrite | Level 9

I do not understand.

subobscure
Obsidian | Level 7
  1. scan the date using spaces as delimiter
  2. Convert the date to numeric
  3. Subtract one value from the other

data a;
date1="2/9/2017 1950";
date2="2/10/2017 1421";

diff=input(scan(date2,1," "),ddmmyy10.)-input(scan(date1,1," "),ddmmyy10.);
run;sas.JPG

 

desireatem
Pyrite | Level 9

I did not work.

 

data D_HPT;
set D_HPT;
los=input(scan(ADT_out,1," "),ddmmyy10.)-input(scan(ADT_IN,1," "),ddmmyy10.);
run;

Kurt_Bremser
Super User

Post your example dataset (in a data step!), so we can see the content and attributes of your variables.

"It did not work" is about as helpful as "a bicycle tipped over in Beijing". So post the log of your code, and how the result (if there was one) differed from your expectations.


@desireatem wrote:

I did not work.

 

data D_HPT;
set D_HPT;
los=input(scan(ADT_out,1," "),ddmmyy10.)-input(scan(ADT_IN,1," "),ddmmyy10.);
run;


 

desireatem
Pyrite | Level 9

Thank you

desireatem
Pyrite | Level 9

works

 

data D_HPT;
set D_HPT;
los=input(scan(ADT_out,1," "),ddmmyy10.)-input(scan(ADT_IN,1," "),ddmmyy10.)/365;
run;

subobscure
Obsidian | Level 7
Good that I could be of help.
I concur with what @Kurt_Bremser said. If a piece of code is not working for you, you are supposed to give the snapshot of your log

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