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,
data want;
str='A_quick_brown_fox_01' ;
length want $30;
do _i=3,4;
want=catx('_',want,scan(str,_i,'_'));
end;
drop _:;
run;
@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;
data want;
str='A_quick_brown_fox_01' ;
length want $30;
do _i=3,4;
want=catx('_',want,scan(str,_i,'_'));
end;
drop _:;
run;
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
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.