I'll start searching for the answer, but thought I'd put the question here first:
How would one add a character string to every value of some variable?
i.e., Variable is Item...
apple
banana
grape
becomes:
apple_fruit
banana_fruit
grape_fruit
Solution greatly appreciated!
Or
newvar = cats(item,'_fruit');
or
newvar = strip(item)||'_fruit';
The || operator may leave some spaces you don't want in the result.
You likely need to create a new variable as the length of the variable item is already set and adding additional characters may exceed that length, or play some games with a Length statement if you want to use the same variable name.
This would look like (assumes making the variable length 25 will hold existing text plus the text you intend to add)
data want; length item $ 25; set have; item= cats(item,'_fruit'); run;
The above would have a possibly unwanted behavior; item becomes the first column in the data set which some people have issues with column order;
just put newvar=item||'_fruit' in a data step.
Or
newvar = cats(item,'_fruit');
or
newvar = strip(item)||'_fruit';
The || operator may leave some spaces you don't want in the result.
You likely need to create a new variable as the length of the variable item is already set and adding additional characters may exceed that length, or play some games with a Length statement if you want to use the same variable name.
This would look like (assumes making the variable length 25 will hold existing text plus the text you intend to add)
data want; length item $ 25; set have; item= cats(item,'_fruit'); run;
The above would have a possibly unwanted behavior; item becomes the first column in the data set which some people have issues with column order;
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 16. 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.