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

Hello!

 

I need to extract a medication class that is between two delimiters that are the same. In this case, it is a semi-colon (;).

 

have (oldvar) = ATC|R|RESPIRATORY SYSTEM; ATC|R03|DRUGS FOR OBSTRUCTIVE AIRWAY DISEASES; ATC|R03A|ADRENERGICS, INHALANTS; ...

 

want (newvar) = ATC|R03|DRUGS FOR OBSTRUCTIVE AIRWAY DISEASES

 

can you suggest an effective way to do this?

 

Thank you!  

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

is it always in 2nd position?

 

if yes, extract the 2nd

 


data test;
have='ATC|R|RESPIRATORY SYSTEM; ATC|R03|DRUGS FOR OBSTRUCTIVE AIRWAY DISEASES; ATC|R03A|ADRENERGICS, INHALANTS; ATC|R03AC|SELECTIVE BETA-2-ADRENORECEPTOR AGONISTS; PRODUCT|001395 01 001|SALBUTAMOL; PRODUCTSYNONYM|001395 01 002|VENTOLIN /00139501/;';
want=strip(scan(have,2,';'));
run;

 

 

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

do you mean this?

data test;
have=' ATC|R|RESPIRATORY SYSTEM; ATC|R03|DRUGS FOR OBSTRUCTIVE AIRWAY DISEASES';
want=scan(have,-1,';','m');
run;

or just this?

 


data test;
have=' ATC|R|RESPIRATORY SYSTEM; ATC|R03|DRUGS FOR OBSTRUCTIVE AIRWAY DISEASES';
want=scan(have,-1,';');
run;

 

mglogan
Obsidian | Level 7

Thanks for the quick response!

 

I should have included the entire length of the string which is as follows:

 

ATC|R|RESPIRATORY SYSTEM; ATC|R03|DRUGS FOR OBSTRUCTIVE AIRWAY DISEASES; ATC|R03A|ADRENERGICS, INHALANTS; ATC|R03AC|SELECTIVE BETA-2-ADRENORECEPTOR AGONISTS; PRODUCT|001395 01 001|SALBUTAMOL; PRODUCTSYNONYM|001395 01 002|VENTOLIN /00139501/;

novinosrin
Tourmaline | Level 20

is it always in 2nd position?

 

if yes, extract the 2nd

 


data test;
have='ATC|R|RESPIRATORY SYSTEM; ATC|R03|DRUGS FOR OBSTRUCTIVE AIRWAY DISEASES; ATC|R03A|ADRENERGICS, INHALANTS; ATC|R03AC|SELECTIVE BETA-2-ADRENORECEPTOR AGONISTS; PRODUCT|001395 01 001|SALBUTAMOL; PRODUCTSYNONYM|001395 01 002|VENTOLIN /00139501/;';
want=strip(scan(have,2,';'));
run;

 

 

mglogan
Obsidian | Level 7

It will always be between the first and second semi-colon.

novinosrin
Tourmaline | Level 20

ok, i updated in my previous. check that out plz

 

here again

 

data test;
have='ATC|R|RESPIRATORY SYSTEM; ATC|R03|DRUGS FOR OBSTRUCTIVE AIRWAY DISEASES; ATC|R03A|ADRENERGICS, INHALANTS; ATC|R03AC|SELECTIVE BETA-2-ADRENORECEPTOR AGONISTS; PRODUCT|001395 01 001|SALBUTAMOL; PRODUCTSYNONYM|001395 01 002|VENTOLIN /00139501/;';
want=strip(scan(have,2,';'));
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 6844 views
  • 0 likes
  • 2 in conversation