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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1856 views
  • 1 like
  • 3 in conversation