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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 7373 views
  • 0 likes
  • 2 in conversation