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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 7485 views
  • 0 likes
  • 2 in conversation