How to delete exact words in variables. 
Posted: 06 October 2013 03:27 PM   [ Ignore ]
Jr. Member
RankRank
Total Posts:  34
Joined  2013-03-31

Hi friends,

The format of a variable is like this:

54361P(P)~U$

I want to delete (P)~U$ in this variable. i.e., I want 54361P.

However, when I use code_new=compress(code,”(P)~U$”), the returned is “54361”.

I wonder, how can I get the outcome like “54361P”?

I think, the problem is that the compress function only compress specific characteristics. What I want to delete is the exact combination of characteristics, i.e., “”(P)~U$”.

Would you help me?

Thank you a lot!

Profile
 
 
Posted: 07 October 2013 07:08 PM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  901
Joined  2011-09-19

hi luckygirl2009,

If the format is always like this: <<goodpart>>(.)... then you can use the index and substring functions.
See http://www.ats.ucla.edu/stat/sas/faq/index_function.htm
and http://www2.sas.com/proceedings/sugi25/25/cc/25p088.pdf

The idea is to get the position of the first bracket ‘(’, and then take the substring of the variable until this position.

hope this helps,

Joost

 Signature 

To reply/post new questions: Please use the group WRDS/SAS on Google Groups! http://groups.google.com/d/forum/wrdssas

Profile
 
 
Posted: 08 October 2013 03:14 PM   [ Ignore ]   [ # 2 ]
Jr. Member
RankRank
Total Posts:  34
Joined  2013-03-31
Joost Impink - 07 October 2013 07:08 PM

hi luckygirl2009,

If the format is always like this: <<goodpart>>(.)... then you can use the index and substring functions.
See http://www.ats.ucla.edu/stat/sas/faq/index_function.htm
and http://www2.sas.com/proceedings/sugi25/25/cc/25p088.pdf

The idea is to get the position of the first bracket ‘(’, and then take the substring of the variable until this position.

hope this helps,

Joost

Hi Joost,

Thank you a lot for your help! Yes, substring works.

Profile