data _null_;
separator='*';
x='SAS';
y=catx(separator,x);
put y=;
run;
Desired output;
S*A*S
Run a loop over the string that selects single characters with SUBSTR, and concatenate those:
do i = 1 to length(x);
y = catx(separator,substr(x,i,1));
end;
Make sure that the defined length of y is sufficient (at least double the defined length of x minus 1).
Run a loop over the string that selects single characters with SUBSTR, and concatenate those:
do i = 1 to length(x);
y = catx(separator,substr(x,i,1));
end;
Make sure that the defined length of y is sufficient (at least double the defined length of x minus 1).
If the separator does not need to be dynamic, you can "hardcode" it:
do i = 1 to length(x);
y = catx('*',substr(x,i,1));
end;
Please supply example data in a data step with datalines (DO NOT SKIP THIS!), and the code you ran against that dataset, and indicate where the result does not meet your expectations.
My bad, y was missing as argument to the CATX function:
data s;
x = 'SAS';
length y $5;
do i = 1 to length(x);
y = catx('*',y,substr(x,i,1));
end;
drop i;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.