Hi,
I am studying for the Base Certification Exam and I have some questions over how SAS assigns length to VARs after using a character function such as CATX. So here are the things I think I know with CATX:
a) the default byte length is 200
b) the length statement can define the byte lenght to anything (when used at the top of the data step)
c) the newly created VAR from CATX will assume the byte length of all the concatenated values such as byte 5!! byte2!! byte7 = NewCharacterVAR of 14bytes
My question then is, when are any of the character manipulation functions returning a value of 200 when separating and concatenating? You are always creating a new character value when using these, correct? So are they not always going to be the sum of the VARs that make them up? I am really confused over the rules of character manipulation and anyone who could shed some light on this or point me in the direction of additional reading material would be greatly appreciated.
Thanks for all your help and time -
The best way to know is to test! Write some code and see what SAS does with it!
The key thing is that you should always define your variables instead of forcing SAS to guess what you want.
If it knows nothing about the variable other than that it is character then it will default to $8.
input str $ ;
But if it can see that you are creating the variable from other variables then if can try to figure out how big it should be.
length x $10;
y=x;
It can even figure some that involve operators or functions.
length a b c $10;
x =a||b;
y=substr(c,1,5);
But in general when it cannot figure out length of the function result will be for every possible input then it will use $200.
length a b c $50;
x = catx(',',a,b,c);
Also watch out for using these in PROC SQL as some of them have shorter limits on what they can return when used in PROC SQL (at least they used to).
The best way to know is to test! Write some code and see what SAS does with it!
The key thing is that you should always define your variables instead of forcing SAS to guess what you want.
If it knows nothing about the variable other than that it is character then it will default to $8.
input str $ ;
But if it can see that you are creating the variable from other variables then if can try to figure out how big it should be.
length x $10;
y=x;
It can even figure some that involve operators or functions.
length a b c $10;
x =a||b;
y=substr(c,1,5);
But in general when it cannot figure out length of the function result will be for every possible input then it will use $200.
length a b c $50;
x = catx(',',a,b,c);
Also watch out for using these in PROC SQL as some of them have shorter limits on what they can return when used in PROC SQL (at least they used to).
Thank you! Testing now
This was very helpful. Viewing the contents of these various scenarios was really helpful to understanding this. Thank you for your help and time.
Reading the documentation can actually help. For instance from the online help for CATX:
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.