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.com
Thank 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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.