🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 10-06-2020 02:50 AM
(2389 views)
data _null_;
separator='*';
x='SAS';
y=catx(separator,x);
put y=;
run;
Desired output;
S*A*S
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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).
8 REPLIES 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data n;
do i = 1 to length(x);
separator='*';
y = catx(separator,substr(x,i,1));
end ;
run;
do i = 1 to length(x);
separator='*';
y = catx(separator,substr(x,i,1));
end ;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
i didn't get desired ouput above code
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data s;
x='SAS';
do i=1 to length(x);
y=catx('*',substr(x,i,1));
end;
run;
x='SAS';
do i=1 to length(x);
y=catx('*',substr(x,i,1));
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Perfect
Thank You
Thank You