BookmarkSubscribeRSS Feed
SIgnificatif
Quartz | Level 8

Hi Dear All.
I'm looking to use sas functions ( not re) to find strings in a plain text.

the text is like this :

data have:
some text blabla, bla right home num8, left home num7 bla bla bla

data want:
the variables left home and right home have the respectives values of num8 nad num7

conditions :
1) the numbers allowed are 0-8
2) the separator between right home with num and the left home and num could be
a space
, ( comma)
.period
'and' word
3) blanks between string num and 0-8 numbers should be removed , sometimes the text could be like right home num 8 ( a space between num and 😎

if there is no right home with num0-8 or left home with num0-8 found write in the respective variables 'not found'.

Thanks for your response.




2 REPLIES 2
Riteshdell
Quartz | Level 8

Your Source data and Desired Output is  not pretty clear, please give information clearly.

SIgnificatif
Quartz | Level 8

Thank you for the message, here are the images and examples:

data have;

texto='some text blablasome text blablasome text blabla
some text blabla, bla right home num8, left home num7 bla bla bla
some text blabla
some text blabla etc ..';
data want;
set have;
 if findw(texto,"right home num8","i")>0 then rh = "num8";
 else if find(texto,"left home num7","i")>0 then lh = "num7";
run;

result:
rh =
lh= num7

Thanks

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1647 views
  • 0 likes
  • 2 in conversation