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

Dear all,

 

how to replace 'AND' (if COUNTRY_CODE='GB'), 'UND'(if COUNTRY_CODE='GE'), 'E'(if COUNTRY_CODE='IT') as '&'?

 

especially, replaced 'AND' should be a single word(i.e., it is 'a and b', rather than 'aandb' )

 

could you please give me some suggestion about this?

thanks in advance.

 

data a;
  infile datalines dlm=',';
  input COUNTRY_CODE $4. name &25;
datalines;
GB, apple and juicande
GB, apple und juicand
GE, plus und flundy
IT, jjeed e dinedd
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You should first make sure that your example code creates the values you want us to manipulate.

Perhaps something like:

data a;
  infile datalines dlm=',' truncover;
  informat COUNTRY_CODE $4. name $25.;
  input COUNTRY_CODE name  4-25 ;
datalines;
GB, apple and juicande
GB, apple und juicand
GE, plus und flundy
IT, jjeed e dinedd
run;

Your example has country_code ending with , and the name blank.

 

 

Second please show exactly what you want for output. Perhaps:

data a;
  infile datalines dlm=',' truncover;
  informat COUNTRY_CODE $4. name $25.;
  input COUNTRY_CODE name  4-25 ;
  if  COUNTRY_CODE='GB' then name=tranwrd(name,' and ',' & ');
  if  COUNTRY_CODE='GE' then name=tranwrd(name,' und ',' & ');
datalines;
GB, apple and juicande
GB, apple und juicand
GE, plus und flundy
IT, jjeed e dinedd
run;

Including the leading and trailing spaces for the words and or und and then including them in the replacement string seems to work.

 

View solution in original post

1 REPLY 1
ballardw
Super User

You should first make sure that your example code creates the values you want us to manipulate.

Perhaps something like:

data a;
  infile datalines dlm=',' truncover;
  informat COUNTRY_CODE $4. name $25.;
  input COUNTRY_CODE name  4-25 ;
datalines;
GB, apple and juicande
GB, apple und juicand
GE, plus und flundy
IT, jjeed e dinedd
run;

Your example has country_code ending with , and the name blank.

 

 

Second please show exactly what you want for output. Perhaps:

data a;
  infile datalines dlm=',' truncover;
  informat COUNTRY_CODE $4. name $25.;
  input COUNTRY_CODE name  4-25 ;
  if  COUNTRY_CODE='GB' then name=tranwrd(name,' and ',' & ');
  if  COUNTRY_CODE='GE' then name=tranwrd(name,' und ',' & ');
datalines;
GB, apple and juicande
GB, apple und juicand
GE, plus und flundy
IT, jjeed e dinedd
run;

Including the leading and trailing spaces for the words and or und and then including them in the replacement string seems to work.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 396 views
  • 1 like
  • 2 in conversation