BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Junyong
Pyrite | Level 9

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 &note;

data _null_;
	infile 'del mylog.log' pipe;
run;

Thanks for any helpful suggestions.

1 ACCEPTED SOLUTION

Accepted Solutions
1 REPLY 1
Patrick
Opal | Level 21

SAS will create and populate two automatic macro variables.

PROC HTTP Response Status Reporting

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 500 views
  • 1 like
  • 2 in conversation