Hi All,
In my variable there are multiple URL were entered , but not in sequence. I need to filter all the URL in new dataset. Below is the sample data .
data have;
infile cards ;
input url & $5000.;
cards;
https://www.youtube.com/w ahsjskjk https://www.yahoo.com jhjkj https://www.google.com
;
run;
Output want:
URL
https://www.youtube.com/w https://www.yahoo.com https://www.google.comThank you in advance 🙂
Count through "words" separated by blanks, identify those beginning with the wanted token, and concatenate to a new string:
data have;
infile cards ;
input url & $5000.;
cards;
https://www.youtube.com/w ahsjskjk https://www.yahoo.com jhjkj https://www.google.com
;
data want;
set have (rename=(url=_url));
length url $5000;
do _i = 1 to countw(_url," ");
_word = scan(_url,_i," ");
if substr(_word,1,4) = "http" then url = catx(" ",url,_word);
end;
drop _:;
run;
Count through "words" separated by blanks, identify those beginning with the wanted token, and concatenate to a new string:
data have;
infile cards ;
input url & $5000.;
cards;
https://www.youtube.com/w ahsjskjk https://www.yahoo.com jhjkj https://www.google.com
;
data want;
set have (rename=(url=_url));
length url $5000;
do _i = 1 to countw(_url," ");
_word = scan(_url,_i," ");
if substr(_word,1,4) = "http" then url = catx(" ",url,_word);
end;
drop _:;
run;
Hi @singhsahab
Here is another approach:
proc sql noprint;
select max(countw(url,' ')), max(count(url,"http")) into:nb1,:nb2 from have;
quit;
data want;
set have;
array _URL (&nb1) $ 200;
array URL_ (&nb2) $ 200;
do i=1 to countw(url,' ');
if prxmatch('/http/',scan(url,i,' ')) then _URL(i) = scan(url,i,' ');
end;
URL_extract = catx(',',of _URL(*));
do j=1 to count(url,"http");
URL_(j) = scan(URL_extract,j,',');
end;
drop i j URL_extract _:;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.