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

Hello Community,

 

I've got a pretty advanced task and I have absolutely no idea how to do this. So feel free to help 🙂

I have a variable "medicinalproduct", which contains a lot of different informations. One information is the API Code (as you can see in the picture). The Code itself has always the same sequence. It always starts with a letter, then its 2 numbers, 2 letters, 2 numbers(for example in the first line, the API Code is B03XA01. I need to extract this code from the variable and have to create a new variable called API.

How can I do this? I have absolutely no idea. Does anybody know?Thank you soo much for your help. Cheers, Mary.The Variable I need to extract the API Code fromThe Variable I need to extract the API Code fromproc_contents.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
HB
Barite | Level 11 HB
Barite | Level 11

Please post data in the form of a data step and not a picture.

 

This is a fit for PRXMATCH I think.

 

With

data textfield;
   input medicinalproduct $100. ;
datalines;
upon a 23234night both dampB03XA01 and dreary GX334&$% when I was so4789 very weary%%$
there came a raven L01XA03 knocking at my door
it was the bV08AB09Rest of time and the worst of ravens
;

data apicodes;
	set textfield;
	startpos = prxmatch('[[A-Z]{1}[0-9]{2}[A-Z]{2}[0-9]{2}]', medicinalproduct);
	apicode = substr(medicinalproduct, startpos, 7);
run;

I can get

The SAS System    
     
medicinalproduct startpos apicode
upon a 23234night both dampB03XA01 and dreary GX334&$% when I was so4789 very weary%%$ 28 B03XA01
there came a raven L01XA03 knocking at my door 20 L01XA03
it was the bV08AB09Rest of time and the worst of ravens 13 V08AB09

 

 

Perhaps that is helpful.

 

I am terrible at regex development so somebody else here can probably make you a much terser expression.

 

View solution in original post

3 REPLIES 3
marysmith
Calcite | Level 5

Hello Community,

 

I've got a pretty advanced task and I have absolutely no idea how to do this. So feel free to help 🙂

I have a variable "medicinalproduct", which contains a lot of different informations. One information is the API Code (as you can see in the picture). The Code itself has always the same sequence. It always starts with a letter, then its 2 numbers, 2 letters, 2 numbers(for example in the first line, the API Code is B03XA01. I need to extract this code from the variable and have to create a new variable called API.

How can I do this? I have absolutely no idea. Does anybody know?Thank you soo much for your help.

Cheers, Mary.

 

meds.PNG

HB
Barite | Level 11 HB
Barite | Level 11

Please post data in the form of a data step and not a picture.

 

This is a fit for PRXMATCH I think.

 

With

data textfield;
   input medicinalproduct $100. ;
datalines;
upon a 23234night both dampB03XA01 and dreary GX334&$% when I was so4789 very weary%%$
there came a raven L01XA03 knocking at my door
it was the bV08AB09Rest of time and the worst of ravens
;

data apicodes;
	set textfield;
	startpos = prxmatch('[[A-Z]{1}[0-9]{2}[A-Z]{2}[0-9]{2}]', medicinalproduct);
	apicode = substr(medicinalproduct, startpos, 7);
run;

I can get

The SAS System    
     
medicinalproduct startpos apicode
upon a 23234night both dampB03XA01 and dreary GX334&$% when I was so4789 very weary%%$ 28 B03XA01
there came a raven L01XA03 knocking at my door 20 L01XA03
it was the bV08AB09Rest of time and the worst of ravens 13 V08AB09

 

 

Perhaps that is helpful.

 

I am terrible at regex development so somebody else here can probably make you a much terser expression.

 

marysmith
Calcite | Level 5
Thank you so much!!!!!!!!!!

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
  • 3 replies
  • 1638 views
  • 3 likes
  • 2 in conversation