DATA Step, Macro, Functions and more

SAS query

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 145
Accepted Solution

SAS query

Dear All,

 

I have dataset with the one variable X. I would like to write a query to exclude the first numerical, special character part and start reading from the first occurrence of the alphabet.

 

10 - SEASONAL ALLERGIES - UN/UNK/1954

3333 ** COMMON COLD - 10/JAN/2015

222 ### RECURRENT SINUSITIS - UN/UNK/2003

44444 @@ INSOMNIA - UN/UNK/2008

The output should look like this.

 

SEASONAL ALLERGIES - UN/UNK/1954

COMMON COLD - 10/JAN/2015

RECURRENT SINUSITIS - UN/UNK/2003

INSOMNIA - UN/UNK/2008

 

Thanks in advance

Rakesh


Accepted Solutions
Solution
‎06-09-2016 12:52 PM
Super User
Super User
Posts: 6,502

Re: SAS query

You could use the VERIFY() function.

 

data have;
  input x $60.;
cards4;
10 - SEASONAL ALLERGIES - UN/UNK/1954
3333 ** COMMON COLD - 10/JAN/2015
222 ### RECURRENT SINUSITIS - UN/UNK/2003
44444 @@ INSOMNIA - UN/UNK/2008
;;;;

data want ;
 set have ;
 x=substr(x,max(1,verify(x,'012345678 -+*#@')));
run;

View solution in original post


All Replies
Solution
‎06-09-2016 12:52 PM
Super User
Super User
Posts: 6,502

Re: SAS query

You could use the VERIFY() function.

 

data have;
  input x $60.;
cards4;
10 - SEASONAL ALLERGIES - UN/UNK/1954
3333 ** COMMON COLD - 10/JAN/2015
222 ### RECURRENT SINUSITIS - UN/UNK/2003
44444 @@ INSOMNIA - UN/UNK/2008
;;;;

data want ;
 set have ;
 x=substr(x,max(1,verify(x,'012345678 -+*#@')));
run;
Super User
Super User
Posts: 7,407

Re: SAS query

You could also substr from the first occurence of an alphabetic character:

new_var=substr(findc(old_var,"","a"));

 

This will substring from first alpha character to the end.

Super User
Posts: 9,682

Re: SAS query

I don't like Tom's code .



data have;
  input x $60.;
cards4;
10 - SEASONAL ALLERGIES - UN/UNK/1954
3333 ** COMMON COLD - 10/JAN/2015
222 ### RECURRENT SINUSITIS - UN/UNK/2003
44444 @@ INSOMNIA - UN/UNK/2008
;;;;


data want ;
 set have ;
 x=substr(x,max(1,verify(x,'012345678 -+*#@')));
 me=substr(x,prxmatch('/[a-z]/i',x));
run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 188 views
  • 1 like
  • 4 in conversation