BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
moorem30
Calcite | Level 5

I am fairly new to SAS and have inherited someone else's code. I noticed the below state in the code is where you see a change in the character length of the provider name. Prior to this step the character length for provider name = 50, after this step the provider name = 14 characters. Is anyone able to tell me why this is happening? Does the character length need to be set since applying an if statement and name change?

 

data HRC_4b;
set HRC_4;
format homecare_BEGIN_DATE datetime20.;
format homecare_BEGIN_DATE2 DISCHARGE_DATE2 date9.;

HOMECARE_BEGIN_DATE = SERVICE_BEGIN_DATE;
HOMECARE_BEGIN_DATE2 = datepart(SERVICE_BEGIN_DATE);
DISCHARGE_DATE2 = datepart(DISCHARGE_DATE);
HOMECARE_PROVIDER_ID = PROVIDER_ID;

if provider_id="1111111" then HOMECARE_PROVIDER_NAME="ABC of Tenango";
else if provider_id="222222" then HOMECARE_PROVIDER_NAME="ABC of Indiana County";
else HOMECARE_PROVIDER_NAME = PROVIDER_NAME;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@moorem30 wrote:

I am fairly new to SAS and have inherited someone else's code. I noticed the below state in the code is where you see a change in the character length of the provider name. Prior to this step the character length for provider name = 50, after this step the provider name = 14 characters.
set HRC_4;
format homecare_BEGIN_DATE datetime20.;
format homecare_BEGIN_DATE2 DISCHARGE_DATE2 date9.;

HOMECARE_BEGIN_DATE = SERVICE_BEGIN_DATE;
HOMECARE_BEGIN_DATE2 = datepart(SERVICE_BEGIN_DATE);
DISCHARGE_DATE2 = datepart(DISCHARGE_DATE);
HOMECARE_PROVIDER_ID = PROVIDER_ID;

if provider_id="1111111" then HOMECARE_PROVIDER_NAME="ABC of Tenango";
else if provider_id="222222" then HOMECARE_PROVIDER_NAME="ABC of Indiana County";
else HOMECARE_PROVIDER_NAME = PROVIDER_NAME;


I assume you mean ... please confirm this is what you mean ... that PROVIDER_NAME is length 50 while HOMECARE_PROVIDER_NAME is length 14.

 

If so, yes you need a length statement

 

length homecare_provide_name $ 50;

 

before HOMECARE_PROVIDER_NAME is used. Why? Because the first time HOMECARE_PROVIDER_NAME is used in the code, it is assigned a length long enough to fit whatever the text length is, it is assigned a length to be the length of "ABC of Tenango", which is apparently 14. If you put the LENGTH statement before that, then HOMECARE_PROVIDER_NAME has length 50.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

@moorem30 wrote:

I am fairly new to SAS and have inherited someone else's code. I noticed the below state in the code is where you see a change in the character length of the provider name. Prior to this step the character length for provider name = 50, after this step the provider name = 14 characters.
set HRC_4;
format homecare_BEGIN_DATE datetime20.;
format homecare_BEGIN_DATE2 DISCHARGE_DATE2 date9.;

HOMECARE_BEGIN_DATE = SERVICE_BEGIN_DATE;
HOMECARE_BEGIN_DATE2 = datepart(SERVICE_BEGIN_DATE);
DISCHARGE_DATE2 = datepart(DISCHARGE_DATE);
HOMECARE_PROVIDER_ID = PROVIDER_ID;

if provider_id="1111111" then HOMECARE_PROVIDER_NAME="ABC of Tenango";
else if provider_id="222222" then HOMECARE_PROVIDER_NAME="ABC of Indiana County";
else HOMECARE_PROVIDER_NAME = PROVIDER_NAME;


I assume you mean ... please confirm this is what you mean ... that PROVIDER_NAME is length 50 while HOMECARE_PROVIDER_NAME is length 14.

 

If so, yes you need a length statement

 

length homecare_provide_name $ 50;

 

before HOMECARE_PROVIDER_NAME is used. Why? Because the first time HOMECARE_PROVIDER_NAME is used in the code, it is assigned a length long enough to fit whatever the text length is, it is assigned a length to be the length of "ABC of Tenango", which is apparently 14. If you put the LENGTH statement before that, then HOMECARE_PROVIDER_NAME has length 50.

--
Paige Miller
moorem30
Calcite | Level 5

Okay, makes sense. Thank you!