BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rakeshvvv
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

3 REPLIES 3
Tom
Super User Tom
Super User

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;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Ksharp
Super User
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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 732 views
  • 1 like
  • 4 in conversation