Resources

SAS/ETS 12.3 User's Guide

Reading Sample Data from a URL

You can use a DATA step to read sample data directly from the URL of a SAS/ETS example. Specify the URL in an INFILE statement; the DATA step reads from the HTML source of that URL. To determine the URL of a SAS/ETS example, select the example from the Example Programs (Sample Library). The following DATA steps read from the Seasonal Model for the Airline Series example for PROC ARIMA, whose URL is http://support.sas.com/documentation/onlinedoc/ets/ex_code/121/ariex02.html.


Writing Data to the SAS Log

The following DATA step writes to the SAS log the HTML lines that start with the line following the <pre> tag and end with the line prior to the </pre> tag.

data _null_;
infile 'http://support.sas.com/documentation/onlinedoc/ets/ex_code/121/ariex02.html'
device=url;
retain pre 0;
input;
if index(_infile_, '</pre>') then pre = 0;
if pre then put _infile_;
if index(_infile_, '<pre>') then pre = 1;
run;

Submitting the Sample to SAS

The following DATA step writes to a file (junk.junk) the HTML lines that start with the line following the <pre> tag and end with the line prior to the </pre> tag. The %INC statement submits the file to SAS.

data _null_;
infile 'http://support.sas.com/documentation/onlinedoc/ets/ex_code/121/ariex02.html'
device=url;
file 'junk.junk';
retain pre 0;
input;
if index(_infile_, '</pre>') then pre = 0;
if pre then put _infile_;
if index(_infile_, '<pre>') then pre = 1;
run;

%inc 'junk.junk' / nosource;

Submitting the Sample, Title, and Comment Block to SAS

The following DATA step writes to a file (junk.junk) the initial comment block, the title, and the HTML lines that start with the line following the <pre> tag and end with a line that contains a single semicolon in the first column. The %INC statement submits the file to SAS.

data _null_;
infile 'http://support.sas.com/documentation/onlinedoc/ets/ex_code/121/ariex02.html'
device=url;
file 'junk.junk';
retain pre 0;
input;
if pre then put _infile_;
if _infile_ eq ';' then pre = 0;
if index(_infile_, '<pre>') then pre = 1;
run;

%inc 'junk.junk' / nosource;


Not all samples end their DATA steps with a single semicolon in the first column. Depending on the sample you are reading, you might need to change the statement IF _INFILE_ EQ ';' THEN PRE = 0;. For example, if the semicolon that ends the instream data set in the sample is in the fourth column instead of the first column, replace ';' with '   ;'. That is, insert three spaces before the semicolon but inside the single quotation marks.