BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
JeffSAS
Fluorite | Level 6

I want to extract the table name from the strings.

data a;
input x $65.;
cards;
if p < 0.5 then no error: put the table abc.story_chapt_2 on the floor
if p > 1.0 then with error: put the table def.cheeze on the floor
if p < 0.5 then no error: put the table xyz.fiction_book4 on the floor
;
run;

the output i want is 

abc.story_chapt_2
def.cheeze
xyz.fiction_book4

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data a;
input x $65.;
pid=prxparse('/[_a-z]\w*\.[_a-z]\w*/');
call prxsubstr(pid,x,p,l);
if p then want=substr(x,p,l);
drop pid p l;
cards;
if p < 0.5 then no error: put the table abc.story_chapt_2 on the floor
if p > 1.0 then with error: put the table def.cheeze on the floor
if p < 0.5 then no error: put the table xyz.fiction_book4 on the floor
;
run;

View solution in original post

2 REPLIES 2
ballardw
Super User

Will the name always follow the word "table"? If so this works, at least for your example

data a;
input x $65.;
length tablename $ 41;
tablename =scan(x,findw(x,'TABLE',' ','IE',1)+1,' ');
cards;
if p < 0.5 then no error: put the table abc.story_chapt_2 on the floor
if p > 1.0 then with error: put the table def.cheeze on the floor
if p < 0.5 then no error: put the table xyz.fiction_book4 on the floor
;
run;
Ksharp
Super User
data a;
input x $65.;
pid=prxparse('/[_a-z]\w*\.[_a-z]\w*/');
call prxsubstr(pid,x,p,l);
if p then want=substr(x,p,l);
drop pid p l;
cards;
if p < 0.5 then no error: put the table abc.story_chapt_2 on the floor
if p > 1.0 then with error: put the table def.cheeze on the floor
if p < 0.5 then no error: put the table xyz.fiction_book4 on the floor
;
run;

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

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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