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.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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