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

I am running this code and it keeps warning me that the variable StateCd has multiple lengths specified. The variable must be named StateCd, so how can I fix this? I have attached my code below.

Thank you

 

 

 

DATA HypTabs.States (LABEL = 'Study States');
ATTRIB StateNum LABEL = 'State Number' LENGTH = 8
StateCd LABEL = 'State Code' LENGTH = $2
StateNm LABEL = 'State Name' LENGTH = $20;
SET HypImpt.States;
BY StateNum;
RUN;

PROC CONTENTS DATA = HypTabs.States VARNUM;
RUN;
PROC PRINT DATA = HypTabs.States;
RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

You define a length for StateCD but this variable already exists in your source data set with a different length.

If you really want to change the length then you will have to create a new variable with the same name.

data ds1;
  length stateCd $4;
  stateCd='ABCD';
  output;
  stop;
run;

data ds2;
  length stateCD $2;
  set ds1(rename=(stateCD=_stateCD));
  stateCD=_stateCD;
  drop _stateCD;
run;

Be aware that like in the code above if the new variable has a shorter length than the string from your source variable, the string might get truncated. 

View solution in original post

4 REPLIES 4
Patrick
Opal | Level 21

You define a length for StateCD but this variable already exists in your source data set with a different length.

If you really want to change the length then you will have to create a new variable with the same name.

data ds1;
  length stateCd $4;
  stateCd='ABCD';
  output;
  stop;
run;

data ds2;
  length stateCD $2;
  set ds1(rename=(stateCD=_stateCD));
  stateCD=_stateCD;
  drop _stateCD;
run;

Be aware that like in the code above if the new variable has a shorter length than the string from your source variable, the string might get truncated. 

walkerel
Calcite | Level 5

Thank you for the help! I got the problem solved!

Astounding
PROC Star
Before changing anything, examine StateCd in your original data. Verify that all.the values are no more than 2 characters long.

If that's the case, it is OK to run your program and ignore the warning.
Ksharp
Super User

Try option :

options varlenchk=nowarn ;

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