Hi,
Does anybody know a quick way to reverse strings. I basically have some strings like the below;
Germany; Munich
and I want to change them to
Munich; Germany
Would you know a good function to use to do this?
Thanks
Chris
Well, that's not really reversed, just swapped over. You could do:
want=catx(';',scan(have,2,";"),scan(have,1,";"));
I suspect your issue is more complicated than that. I would split the string up into rows of data with one element per row. Then have a look up merge, for country, and one for city, merge that on to get a flag for wether it is a country or city, then transpose it up. Provide some test data in the form of a datastep and can show code.
Well, that's not really reversed, just swapped over. You could do:
want=catx(';',scan(have,2,";"),scan(have,1,";"));
I suspect your issue is more complicated than that. I would split the string up into rows of data with one element per row. Then have a look up merge, for country, and one for city, merge that on to get a flag for wether it is a country or city, then transpose it up. Provide some test data in the form of a datastep and can show code.
Thanks a lot for your advice
data x;
a='Munich; Germany';
b=catt(scan(a,2,";"),"; ",scan(a,1,";"));
run;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.