Hi @112211, I didn't see your desired output until now.
data want (drop = i);
length a_want $50.; /* Needs to be set depending on output */
a = "United States of America";
do i = countw(a, " ") to 1 by -1;
a_want = catx(" ", a_want, scan(a, i, " "));
end;
run;
Basically, your loop starts at 4 because COUNTW finds four words. I use the by -1 to go from 4 --> 3 --> 2 -- 1.
CATX then combines each word with the DO loop.
Use the REVERSE function, no loops needed
data want;
set do;
reverse_A=reverse(A);
run;
Hi @112211, I didn't see your desired output until now.
data want (drop = i);
length a_want $50.; /* Needs to be set depending on output */
a = "United States of America";
do i = countw(a, " ") to 1 by -1;
a_want = catx(" ", a_want, scan(a, i, " "));
end;
run;
Basically, your loop starts at 4 because COUNTW finds four words. I use the by -1 to go from 4 --> 3 --> 2 -- 1.
CATX then combines each word with the DO loop.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.