BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cmoore
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

cmoore
Obsidian | Level 7

Thanks a lot for your advice

ShiroAmada
Lapis Lazuli | Level 10
data x;
  a='Munich; Germany';
  b=catt(scan(a,2,";"),"; ",scan(a,1,";"));
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 752 views
  • 0 likes
  • 3 in conversation