Hi, I was just doing something similar, extracting a word of a string into a different variable and some words got truncated because of the default length of an array is set to 8.
The way to go around it is to put a really big length for the array.
My code is as follows:
data work.smallranges_desc1;
set work.smallranges;
array word {&maxlength.} $100.;
do i=1 to &maxlength.;
word[i]=scan(range,i);
end;
run;
I think you may be confusing the number of occurrences of the array with the length.
@Elle wrote:
array word {&maxlength.} $100.;
What you have in {braces} is not the length. $100 is the length of each variable in the array. "&maxlength" is not a length at all but rather is the number of occurrences in the array.
For example, let's say I have some variables in a SAS dataset. Each variable is character. The names of the variables are Animal1 - Animal6. Let's say each variable is $32.
I would declare the array as follows:
ARRAY Animals {6} $32 Animal1 - Animal6;
The number "6" is not a length but the number of occurrences. $32 is the length of each occurrence.
For example, say I have the following SAS code:
DATA Have;
INPUT Animal1 : $32.
Animal2 : $32.
Animal3 : $32.
Animal4 : $32.
Animal5 : $32.
Animal6 : $32.
;
DATALINES;
bird cat aardvark tarantula tapir elephant
dog owl mouse hippopotamus lamb lemur
panda piranha parakeet pig peacock penquin
armadillo fringehead jellyfish alligator wallaby pademelon
;
RUN;
DATA Want;
DROP _:;
SET Have;
ARRAY Animals {6} $8 Animal1 - Animal6;
DO _i = 1 TO 6;
Animals{_i} = PROPCASE(Animals{_i});
END;
RUN;
PROC PRINT DATA = Want;
RUN;
My array definition is
ARRAY Animals {6} $8 Animal1 - Animal6;
Notice my results: Some of the names are truncated.
Now, change the array definition from $8 to $32:
ARRAY Animals {6} $32 Animal1 - Animal6;
In the results, the truncation is gone.
In both of my definitions, the number of occurrences was {6}. This did not change. The length of each variable however did change. It went from $8 to $32. The length definition is what you need to change in order to fix truncation, not the number of occurrences.
First definition (too short): ARRAY Animals {6} $8 Animal1 - Animal6;
Second definition (correct) ARRAY Animals {6} $32 Animal1 - Animal6;
Jim
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!
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.
Ready to level-up your skills? Choose your own adventure.