Suppose I am interested in the following two pages.
https://news.ycombinator.com/news?p=1 https://news.ycombinator.com/news?p=2
I can feed these two addresses and collectively read them using FILEVAR. Just one issue is that I want each observation to be each word rather than each line. I coded as follows.
data url;
do i=1 to 2;
url='https://news.ycombinator.com/news?p='||strip(i);
output;
end;
drop i;
run;
data htm;
set url;
infile i url filevar=url truncover end=e column=c length=l;
do until(e);
do j=1 by 1 until(c>l);
input htm :$32767. @;
output;
end;
end;
run;
Then I found that there is an infinite loop and SAS cannot read the pages correctly. I tried to change the order of two do loops but failed too. What am I doing wrong?
You never switch to a new line within your outer loop, so the end condition (e) will never be reached. Add an explicit input:
data htm;
set url;
infile i url filevar=url truncover end=e column=c length=l;
do until(e);
do j=1 by 1 until(c>l);
input htm :$32767. @;
output;
end;
input;
end;
run;
You never switch to a new line within your outer loop, so the end condition (e) will never be reached. Add an explicit input:
data htm;
set url;
infile i url filevar=url truncover end=e column=c length=l;
do until(e);
do j=1 by 1 until(c>l);
input htm :$32767. @;
output;
end;
input;
end;
run;
Very appreciate. I was looking at this document, but it does not use two INPUTs—does my code require another INPUT because of @?
Your @ keeps your line pointer in the same line. Since you also do not skip to the next data step iteration when you've read a line (because of the outer loop), no implicit input is executed that would put you in the next input line automatically. So you have to supply that skip to the next line yourself.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: