DATA Step, Macro, Functions and more

How to extract an information from a variable and create a new variabl with it?

Accepted Solution Solved
Reply
Contributor
Posts: 37
Accepted Solution

How to extract an information from a variable and create a new variabl with it?

[ Edited ]

Hello Community,

 

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

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.PNGThe Variable I need to extract the API Code fromproc_contents.JPG


Accepted Solutions
Solution
‎01-15-2018 05:14 AM
Super Contributor
Super Contributor
Posts: 260

Re: How to extract information from a variable and create a new variable with it?

[ Edited ]
Posted in reply to marysmith

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


All Replies
Contributor
Posts: 37

How to extract information from a variable and create a new variable with it?

Posted in reply to marysmith

Hello Community,

 

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

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

Solution
‎01-15-2018 05:14 AM
Super Contributor
Super Contributor
Posts: 260

Re: How to extract information from a variable and create a new variable with it?

[ Edited ]
Posted in reply to marysmith

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.

 

Contributor
Posts: 37

Re: How to extract information from a variable and create a new variable with it?

Thank you so much!!!!!!!!!!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 144 views
  • 3 likes
  • 2 in conversation