BookmarkSubscribeRSS Feed
SIgnificatif
Quartz | Level 8

Hi all,

I'm looking to perform a search for a string and a number based on a template ( variations) this way :

 

%let quant=[quantity0,quantity1,quantity2,quantity3,quantity4,quantity5,quantity6,quantity7,quantity8];

%let fruits=[apples, pears];

%let fruit=[apple, pear];

%let variations=[red &fruits big &quant,red &fruits &quant, blue &fruit &quant, blue &fruits &quant ]; ( and so on... there are many variations, the most imp

 

data have;
mytext ="somedays I'll collect red apples quantity5 and blue pear quantity3 and will eat them " ;
run;

the output is extracting the quantity based on the template variations, in the case of data have:

RA = quantity5 ( for 'red apples quantity 5)

BP = quantity3 ( for 'blue pear quantity 3)


the standard search function is below, anyone knows how to perform a search with sas code ( not regex) with hprovided templates ?

if index(mytext,"red apples quantity 5")^=0 then RA=quantity5

Thanks.

1 REPLY 1
andreas_lds
Jade | Level 19

Why do you exclude regex?

After a quick look at your problem, i can't see any better way to solve this, than by using regex.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 689 views
  • 0 likes
  • 2 in conversation