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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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