DATA Step, Macro, Functions and more

Create a discharge date from admission day and length of stay

Reply
Super Contributor
Posts: 297

Create a discharge date from admission day and length of stay

I have the following data;

 

ADM LOS
20111220 0015
20111225 0007
20111226 0022
20111227 0006
20111227 0009
20111227 0025

 

I want to crest; 

NB one is number ie LOS and ADMI is date format

 

ADMI LOS DISCHARGE_DAY=ADMI+LOS

 

20111220 0015  
20111225 0007  
20111226 0022  
20111227 0006  
20111227 0009  
20111227 0025  
20111229 0004  

 

Then once I have created the discharge variable, I want to change the format of both the ADMI and DISCHARGE_DAY to YYMMDD10. that is the date should be 2012-01-21 not 20120121 as it is.

Trusted Advisor
Posts: 1,131

Re: Create a discharge date from admission day and length of stay

data have;
input    ADM:yymmdd10. 	LOS;
disc=adm+los;
format ADM disc yymmdd10.;
cards;
20111220 	0015
20111225 	0007
20111226 	0022
20111227 	0006
20111227 	0009
20111227 	0025
;
run;
Thanks,
Jag
Super Contributor
Posts: 297

Re: Create a discharge date from admission day and length of stay

I did this but it didnt work.

 

data have1;
set have;
DOA = INPUT(ADM, yymmdd10.);
disc=adm+los;
format ADM disc yymmdd10.;
run;

Super Contributor
Posts: 297

Re: Create a discharge date from admission day and length of stay

I did this but it didnt work;

 

data have1;
set have;
DOA = INPUT(ADM, yymmdd10.);
disc=DOA+los;
format ADM disc yymmdd10.;
run;

Trusted Advisor
Posts: 1,392

Re: Create a discharge date from admission day and length of stay

What did you mean by "it did not work" ?

Please post log and results.

Super Contributor
Posts: 297

Re: Create a discharge date from admission day and length of stay

DOA is character not numeric so, I cannot perform the addition.

 

174 data day30 ;
175 set day30 ;
176 DOA = INPUT(ADMIT_START_OF_CARE, yymmdd10.);
177 disc=ADMIT_START_OF_CARE+LENGTH_OF_STAY;
178 format ADMIT_START_OF_CARE disc yymmdd10.;
179 run;

NOTE: Numeric values have been converted to character values at the places given by:
(Line)Smiley SadColumn).

Trusted Advisor
Posts: 1,131

Re: Create a discharge date from admission day and length of stay

data day30 ;set day30 ;
DOA = INPUT(ADMIT_START_OF_CARE, yymmdd10.);
disc=DOA+LENGTH_OF_STAY;
format ADMIT_START_OF_CARE disc yymmdd10.;
run;
Thanks,
Jag
Super Contributor
Posts: 297

Re: Create a discharge date from admission day and length of stay

SAS Output

Obs DOA LENGTH_OF_STAY ADMIT_START_OF_CARE disc
1 01DEC2020 17 ********** **********
2 02DEC2020 7 ********** **********
3 02DEC2020 2 ********** **********
4 03DEC2020 2 ********** **********
5 02DEC2020 22 ********** **********
Trusted Advisor
Posts: 1,392

Re: Create a discharge date from admission day and length of stay

Change FORMAT line to:

 

format DOA disc yymmdd10.   ADMIT_START_OF_CARE $8.;

See my previous post.

Trusted Advisor
Posts: 1,392

Re: Create a discharge date from admission day and length of stay

If ADMIT_START_OF_CARE is a date, character type, then 

    

DOA = INPUT(ADMIT_START_OF_CARE, yymmdd10.);

will create DOA as numeric.

 

The note you got relates to:

disc=ADMIT_START_OF_CARE+LENGTH_OF_STAY;

and you get wrong result because it adds LENGTH_OF_STAY to the displayed number (like: 20161120) not the date !

 

As ADMIT_START_OF_CARE is a chat type, you can't assign it a format yymmdd10.

You probably meant to write:

format DOA disc yymmdd10.;

 

 

 

 

 

 

Super Contributor
Posts: 297

Re: Create a discharge date from admission day and length of stay

IT is still wrong. I want to have  preserve ADMIT_START_OF_CARE variable. Coming up as XXXXXXXX

 

 

data day30 ;set day30 ;
DOA = INPUT(ADMIT_START_OF_CARE, yymmdd10.);
disc=DOA+LENGTH_OF_STAY;
*format ADMIT_START_OF_CARE disc yymmdd10.;
format DOA disc ADMIT_START_OF_CARE yymmdd10.;
run;

 

SAS Output


Obs DOA LENGTH_OF_STAY ADMIT_START_OF_CARE disc
1 2020-12-01 17 ********** 2020-12-18
2 2020-12-02 7 ********** 2020-12-09
3 2020-12-02 2 ********** 2020-12-04
4 2020-12-03 2 ********** 2020-12-05
5 2020-12-02 22 ********** 2020-12-24
Trusted Advisor
Posts: 1,392

Re: Create a discharge date from admission day and length of stay

if ADMIT_START_OF_CARE is a date why is it assigned to CHAR ($) type ?

 

Assuming you got it from a text file or from excel, change its type and format using:

 

data have1;
 set have(rename=(ADMIT_START_OF_CARE=datex));
       ADMIT_START_OF_CARE = input(datex, yymmdd8.);
        /* assuming it is yyyymmdd informat */
       format ADMIT_START_OF_CARE yymmdd10.;
run;

then change your code to:

data day30 ;
  set have1 ;
       DOA = ADMIT_START_OF_CARE;
       disc=ADMIT_START_OF_CARE + LENGTH_OF_STAY;
       format DOA ADMIT_START_OF_CARE disc yymmdd10.;
run;

You may drop DOA after having ADMIT_START_OF_CARE a numeric date.

 

Super User
Posts: 5,085

Re: Create a discharge date from admission day and length of stay

If ADM is numeric, the correct conversion formula would be:

 

ADMI = input(put(ADM,8.), yymmdd8.);

format admi yymmdd10.;

 

You can still perform math with that.  For example:

 

DISCHARGE_DAY = ADMI + input(LOS, 4.);

format discharge_day yymmdd10.;

 

I'm assuming that LOS is character since it displays with leading zeros.  If it's actually numeric with a permanent Z4 format, you can skip the INPUT function.

Ask a Question
Discussion stats
  • 12 replies
  • 150 views
  • 0 likes
  • 4 in conversation