- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Dear all,
how can I remove all punctuation characters (except '&')?
I using the following codes
data a;
infile datalines dlm=',' truncover;
informat HRM_L2_Step6 $1000. ;
input HRM_L2_Step6 ;
datalines;
!OBAC
1...
1... IPR
1.CALL RESEA-RCH & DESIGN
100% RECYCLED PANEL COMPAMY
20/20 SPEECH
24/7 TECHNOLOGIES
2S-SOFISTIK/EJ/TED SISTEMS
3 S'S
3-D COMPOSITES
3-D COMPOSITS
3COM CORPORATION (COMPUTERS COMMUNICATION COMPATIBILITY CORPORATION)
3M COMPANY (MINNESOTA MINING AND MANUFACTURING COMPANY)
3M INNOVATIVE PROPERTIES COMPANY (MINNESOTA MINING AND MANUFACTURING INNOVATIVE PROPERTIES COMPANY)
3RD ANGLE (U.K.)
3RD ANGLE (U.K.) LTD., HIGHLEY
3RD ANGLE (U.K.) LTD., HIGHLEY, SHROPSHIRE
>>PYROTEX
@ROAD
;
run;
Data b;
Set a;
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"'", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,";", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"^", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"<", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,".", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"`", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"_", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,">", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"''", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"!", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"+", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"?", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"(", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"£", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"{", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"\", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,")", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"$", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"}", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"|", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,",", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"%", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"[", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"¶", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"-", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"*", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"]", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"/", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"@", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,":", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"~", "");
HRM_L2_Step6=tranwrd(HRM_L2_Step6,"#", "");
run;
however, for example, for '!OBAC', I get ' OBAC' rather than 'OBAC'.
How can I get 'OBAC'?
could you please give me some suggestions about this? thanks in advance.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In general, you should be looking at COMPRESS (which removes characters), rather than TRANWRD (which translates them into something else).
For most of your request, you can fit it into a single statement. For example:
HRM_L2_Step6 = compress(HRM_L2_Step6, ";'<.+?/()" );
When you look at the COMPRESS documentation, you may also notice that a third parameter lets you use particular letters to abbreviate a request that applies to groups of characters. You may find an abbreviation within that third parameter that handles most of the characters you are interested in removing:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In general, you should be looking at COMPRESS (which removes characters), rather than TRANWRD (which translates them into something else).
For most of your request, you can fit it into a single statement. For example:
HRM_L2_Step6 = compress(HRM_L2_Step6, ";'<.+?/()" );
When you look at the COMPRESS documentation, you may also notice that a third parameter lets you use particular letters to abbreviate a request that applies to groups of characters. You may find an abbreviation within that third parameter that handles most of the characters you are interested in removing:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
For your consideration:
data example; x="ABC!@#$%^&*()_+=-,./?><;:[]{}\|DEF`"; y=compress(x,,'P'); run;
I didn't go through any additional steps to add the double quote character to X but you get the general idea.