Suppose I download a webpage via PROC HTTP.
filename myfile 'myfile.htm'; proc http url='https://www.macrotrends.net/stocks/charts/KO/cocacola/balance-sheet' out=myfile; run;
Successful downloading returns NOTE: 200 OK as follows:
1 filename myfile 'myfile.htm';
2
3 proc http url='https://www.macrotrends.net/stocks/charts/KO/cocacola/balance-sheet' out=myfile; 4 run; NOTE: 200 OK NOTE: PROCEDURE HTTP used (Total process time): real time 0.05 seconds cpu time 0.00 seconds
Instead, unsuccessful downloading returns NOTE: 429 O as follows:
1 filename myfile 'myfile.htm'; 2 3 proc http url='https://www.macrotrends.net/stocks/charts/KO/cocacola/balance-sheet' out=myfile; 4 run; NOTE: 429 O NOTE: PROCEDURE HTTP used (Total process time): real time 0.05 seconds cpu time 0.00 seconds
Is there any easy way to extract the "200" or "429" as a macro variable? Though I can output the log and infile it with symputx as follows, I wonder if there are easier ways than this.
filename myfile 'myfile.htm';
proc printto log='mylog.log';
run;
proc http url='https://www.macrotrends.net/stocks/charts/KO/cocacola/balance-sheet' out=myfile;
run;
proc printto;
run;
data _null_;
infile 'mylog.log' truncover;
input;
if scan(lag3(_infile_),3)='http' then call symputx('note',scan(_infile_,2));
run;
%put ¬e;
data _null_;
infile 'del mylog.log' pipe;
run;
Thanks for any helpful suggestions.
SAS will create and populate two automatic macro variables.
SAS will create and populate two automatic macro variables.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.