BookmarkSubscribeRSS Feed
desireatem
Pyrite | Level 9

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.

12 REPLIES 12
Jagadishkatam
Amethyst | Level 16
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
desireatem
Pyrite | Level 9

I did this but it didnt work.

 

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

desireatem
Pyrite | Level 9

I did this but it didnt work;

 

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

Shmuel
Garnet | Level 18

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

Please post log and results.

desireatem
Pyrite | Level 9

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):(Column).

Jagadishkatam
Amethyst | Level 16
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
desireatem
Pyrite | Level 9

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 ********** **********
Shmuel
Garnet | Level 18

Change FORMAT line to:

 

format DOA disc yymmdd10.   ADMIT_START_OF_CARE $8.;

See my previous post.

Shmuel
Garnet | Level 18

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

 

 

 

 

 

 

desireatem
Pyrite | Level 9

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
Shmuel
Garnet | Level 18

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.

 

Astounding
PROC Star

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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