BookmarkSubscribeRSS Feed
pdhokriya
Pyrite | Level 9

Hi,

 

How should I handle below special charcters?

 

’ replaced by '

• by space

´ replace by '


data abc;
y="The Subject’s status was not changed";output;
y="The Subject has - •6 point";output;
y="The subject didn´t capture photo";output;
run;

 

data xyz;
set abc ;
y1=tranwrd (y, "’" , "'");
y1=tranwrd (y, "•" ,"");
y1=tranwrd (y, "´" , "'");
run;

3 REPLIES 3
Kurt_Bremser
Super User
data xyz;
set abc ;
y1=tranwrd (y, "’" , "'");
y1=tranwrd (y, "•" ,"");
y1=tranwrd (y, "´" , "'");
run;

Since you always create y1 anew from y, only the last result will show up in your output, overwriting the results of the previous translations. Change this to

data xyz;
set abc ;
y1=tranwrd (y, "’" , "'");
y1=tranwrd (y1, "•" ,"");
y1=tranwrd (y1, "´" , "'");
run;
pdhokriya
Pyrite | Level 9

Yes this is not working, do you have any other solution for this senerio.

Tom
Super User Tom
Super User

You seem to have an encoding issue.  In your post you have two different sets of characters.  One set in the description of the problem and different characters in the code.

image.pngimage.png

So which ones to you have in your actual file?  Look at the Hexadecimal representation of the strings to see  what is actually in the file.

E28099 ’
E280A2 •
C2B4   ´
92     ’
95     •
B4     ´

What encoding is your SAS session using? Check the value of the SYSENCODING macro variable.  What encoding is the dataset that has values using?  Check PROC CONTENTS output for the dataset.

 

You can use hexadecimal constants in your SAS code to make the code more portable.

Run the right code for the encoding that is in the character variable Y.

* UTF-8 codes ;
y1=tranwrd(y, 'E28099'x , "'");
y1=tranwrd(y1,'E280A2'x ," ");
y1=tranwrd(y1, 'C2B4'x , "'");

* WLATIN1 code ;
y1=translate(y,"' '",'929584'x);

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 2059 views
  • 1 like
  • 3 in conversation