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;
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.
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.