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

A SAS Communities page can be easily read as follows:

data page(compress=char);
	do i=1 to 1;
		address=cats("https://communities.sas.com/t5/forums/recentpostspage/post-type/thread/page/",i);
		infile dummy url filevar=address truncover end=j;
		do until(j);
			input page $32767.;
			output;
		end;
	end;
run;

However, the code becomes incorrect if I change DO I=1 TO 1; to DO I=1 TO 10; instead.

data page(compress=char);
	do i=1 to 10;
		address=cats("https://communities.sas.com/t5/forums/recentpostspage/post-type/thread/page/",i);
		infile dummy url filevar=address truncover end=j;
		do until(j);
			input page $32767.;
			output;
		end;
	end;
run;

Can't I repeat INFILE FILEVAR inside DO loops? Though I know that the following code works correctly, I want to know where I'm misunderstanding.

data page;
	do i=1 to 10;
		output;
	end;
run;

data page(compress=char);
	set page;
	address=cats("https://communities.sas.com/t5/forums/recentpostspage/post-type/thread/page/",i);
	infile dummy url filevar=address truncover end=j;
	do until(j);
		input page $32767.;
		output;
	end;
run;

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Really, describe the problem.

 

In this case it is an infinite loop. I set the I loop to do 1 to 2. Then canceled (Ctrl-Break cancel data step) after minute or so. Then run this bit of code.

data junk;
  set page;
  by i notsorted;
  Row=_n_;
  if first.i or last.i;
run;

Which with proc print for my alloted time yields:

--------------------------------------------------------------------------------------------------

i       Row

1         1
1      8331
2      8332
2     16741
1     16742
1     25072
2     25073
2     33482
1     33483
1     41813
2     41814
2     50223
1     50224
1     58554
2     58555
2     66964
1     66965
1     75295
2     75296
2     83705
1     83706
1     92036
2     92037
2    100446

A quick analysis of the above shows that the line intervals for I are the same for each value of i, in other words the input is getting read repeatedly without stopping.

 

Try this approach which follows the second example of using Filevar in reading multiple files in the documentation.

data add;
   length address $ 200;
	do i=1 to 2;
		address=cats("https://communities.sas.com/t5/forums/recentpostspage/post-type/thread/page/",i);
      output;
   end;
run;
data page(compress=char);
      set add;
		infile dummy url filevar=address truncover end=j;
		do until(j);
			input page $32767.;
			output;
		end;
run;

View solution in original post

2 REPLIES 2
Reeza
Super User
What errors are you getting?

The example of a similar type of problem in the documentation does separate the two steps for sure (Example 10 on the INFILE statement in the documentation).
ballardw
Super User

Really, describe the problem.

 

In this case it is an infinite loop. I set the I loop to do 1 to 2. Then canceled (Ctrl-Break cancel data step) after minute or so. Then run this bit of code.

data junk;
  set page;
  by i notsorted;
  Row=_n_;
  if first.i or last.i;
run;

Which with proc print for my alloted time yields:

--------------------------------------------------------------------------------------------------

i       Row

1         1
1      8331
2      8332
2     16741
1     16742
1     25072
2     25073
2     33482
1     33483
1     41813
2     41814
2     50223
1     50224
1     58554
2     58555
2     66964
1     66965
1     75295
2     75296
2     83705
1     83706
1     92036
2     92037
2    100446

A quick analysis of the above shows that the line intervals for I are the same for each value of i, in other words the input is getting read repeatedly without stopping.

 

Try this approach which follows the second example of using Filevar in reading multiple files in the documentation.

data add;
   length address $ 200;
	do i=1 to 2;
		address=cats("https://communities.sas.com/t5/forums/recentpostspage/post-type/thread/page/",i);
      output;
   end;
run;
data page(compress=char);
      set add;
		infile dummy url filevar=address truncover end=j;
		do until(j);
			input page $32767.;
			output;
		end;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 2 replies
  • 660 views
  • 4 likes
  • 3 in conversation