BookmarkSubscribeRSS Feed
Helle
Calcite | Level 5
Hi,

I have a dataset containing the variable "memname". The values of "memname" may contain one or more Danish characters like Æ, Ø and Å. I need to convert these to AE, OE and AA respectively. The new converted values are stored in the variable "memname_dk". Examples of values with Danish characters include "ÅRSOPGØRELSE" and "ANSØGT_VILKÅR".

I have tried to use different loops to make sure that all Danish characters are converted but didn't succeed yet so in the end I decided to simply run three almost identical data steps (see below). However, I am sure there must be a more simple way to do this. Can anybody help me please?

Here's the current solution:
data aa;
set aa;
memname_dk=memname;
if find(memname_dk,'Æ') > 0 then memname_dk=tranwrd(memname,'Æ','AE');
run;
data aa;
set aa
if find(memname_dk,'Ø') > 0 then memname_dk=tranwrd(memname,'Ø','OE');
run;
data aa;
set aa
if find(memname_dk,'Å') > 0 then memname_dk=tranwrd(memname,'Å','AA');
run;

Thanks,

Helle
3 REPLIES 3
Peter_C
Rhodochrosite | Level 12
did you try embedding the tranwrd functions?
data dealt_with ;
set original ;
memname_dk=
tranwrd(
tranwrd(
tranwrd(memname
,'Æ','AE')
,'Ø','OE')
,'Å','AA');
run;
Robert_Bardos
Fluorite | Level 6
First, your design is slightly flawed, since it does not handle strings that contain a combination of these danish characters.

Second, there's no need to spread the function call over three data steps.
Third, there's no actual need for an "if" test.

Just chain the tranword function calls/statements like in e.g.
[pre]
data aa ;
set aa ;
memname_dk = tranwrd(memname,'Æ','AE');
memname_dk = tranwrd(memname_dk,'Ø','OE');
memname_dk = tranwrd(memname_dk,'Å','AA');
run ;
[/pre]
Helle
Calcite | Level 5
Hi,

Thanks a lot for your suggestions - they both give me the desired results 🙂

Regards,

Helle

sas-innovate-2024.png

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.

 

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
  • 1854 views
  • 0 likes
  • 3 in conversation