## date manupulation

Solved
Super Contributor
Posts: 328

# date manupulation

[ Edited ]

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;

 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

Accepted Solutions
Solution
‎07-28-2017 01:57 AM
Super Contributor
Posts: 328

works

data D_HPT;
set D_HPT;
run;

All Replies
Super User
Posts: 23,778

## Re: date manupulation

SCAN to separate components

INPUT to convert character to date

Super Contributor
Posts: 328

## Re: date manupulation

I do not understand.

Occasional Contributor
Posts: 11

## Re: date manupulation

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;``````

Super Contributor
Posts: 328

[ Edited ]

I did not work.

data D_HPT;
set D_HPT;
run;

Super User
Posts: 10,280

## Re: date manupulation

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;
run;

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super Contributor
Posts: 328

## Re: date manupulation

Thank you

Solution
‎07-28-2017 01:57 AM
Super Contributor
Posts: 328

## Re: date manupulation

works

data D_HPT;
set D_HPT;
run;

Occasional Contributor
Posts: 11