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.
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;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.