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
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;
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;
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.