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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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