BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Junyong
Pyrite | Level 9

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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;
Junyong
Pyrite | Level 9

Very appreciate. I was looking at this document, but it does not use two INPUTs—does my code require another INPUT because of @?

Kurt_Bremser
Super User

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 955 views
  • 2 likes
  • 2 in conversation