BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mlogan
Lapis Lazuli | Level 10

Hi there,

I am trying to extract 'brown_fox' from the whole observation 'A_quick_brown_fox_01' with scan function. Can someone please help. The whole idea is to extract 3rd and 4th word separated by underscores.

 

 

Thanks,

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data want;
str='A_quick_brown_fox_01' ;
length want $30;
do _i=3,4;
want=catx('_',want,scan(str,_i,'_'));
end;
drop _:;
run;

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

@mlogan wrote:

Hi there,

I am trying to extract 'brown_fox' from the whole observation 'A_quick_brown_fox_01' with scan function. Can someone please help. The whole idea is to extract 3rd and 4th word separated by underscores.

data abc;
string='A_quick_brown_fox_01_etc_etc_etc';
third=scan(string,3,'_');
fourth=scan(string,4,'_');
want = cats(third,'_',fourth);
run;
--
Paige Miller
novinosrin
Tourmaline | Level 20
data want;
str='A_quick_brown_fox_01' ;
length want $30;
do _i=3,4;
want=catx('_',want,scan(str,_i,'_'));
end;
drop _:;
run;

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1000 views
  • 1 like
  • 3 in conversation