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!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 2688 views
  • 0 likes
  • 2 in conversation