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;
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.
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.
Thank you for the help! I got the problem solved!
Try option :
options varlenchk=nowarn ;
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!
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.