BookmarkSubscribeRSS Feed
Faiz_Qureshi
Calcite | Level 5

Please check the do block is ended properly.

 

 

data output_data;
length response $32000.;
do until (last_obs);
/* Read the JSON string from the input dataset */
set input_data point=_n_;
json_string = compress(json_string, ' ');
 
/* Put the JSON string in an external file */
filename json_in temp;
data _null_;
file json_in;
put json_string;
run;
 
/* Post the JSON query to the API and get the response */
filename resp temp;
proc http
method="POST"
url="url"
ct="application/json"
in=json_in
out=resp;
run;
 
/* Read the response from the API and save it in the output dataset */
data _null_;
infile resp;
input;
response = _infile_;
run;
 
/* Append the response to the output dataset */
output_data = output_data || response;
 
/* Check if this is the last observation */
last_obs = (_n_ = nobs);
end;
run;
 
 
3 REPLIES 3
PaigeMiller
Diamond | Level 26
data output_data;
length response $32000.;
do until (last_obs);
/* Read the JSON string from the input dataset */
set input_data point=_n_;
json_string = compress(json_string, ' ');

 

I don't see any end; statement here. So you have an "unclosed do block".

 

In the future, when you get an error in the log, please show us the LOG for the PROC or DATA step that has the error. We need to see the entire log for this PROC or DATA step, not just the errors.

--
Paige Miller
Kurt_Bremser
Super User

No, your DO block is not ended properly.

data output_data;
length response $32000.;
do until (last_obs);
/* Read the JSON string from the input dataset */
set input_data point=_n_;
json_string = compress(json_string, ' ');
 
/* Put the JSON string in an external file */
filename json_in temp;
data _null_; /* This DATA statement begins a new data step, and therefore ends the previous one. The DO statement is left without an END */

Please describe what data you have, and also what you want to do with it; anyway, nesting DATA/PROC steps is not possible.

Tom
Super User Tom
Super User

Your DO block is not ended.  In fact you didn't even include a RUN statement to end the data step, but SAS will assume you were finished when it sees the start of the PROC HTTP step.

 

You also have some code that belongs in a data step at the end of your program after the last DATA _NULL_ step.  You cannot have a assignment statement that is not part of a data step.

 

One idea you could try is to create a macro that takes the line of JSON text as input and then generate one call to the macro for each line in your original dataset.   Say you made a macro named %POST() then your data step to generate one macro call for each observation might look like:

data _null_;
  set input ;
  call execute(cats('%nrstr(%post)(,quote(trim(JSON),"'"),')'));
run;

So your macro might look like:

%macro post(JSON);
/* Put the JSON string in an external file */
filename json_in temp;
filename resp temp;

data response;
  file json_in;
  length json $4000;
  json=&json;
  put json;
run;
 
/* Post the JSON query to the API and get the response */
proc http
method="POST"
url="url"
ct="application/json"
in=json_in
out=resp;
run;
 
/* Read the response from the API and save it in the output dataset */
data response;
  set response;
  length response $4000;
  infile resp truncover;
  input repsonse $4000.;
run;

proc append data=response base=dataout force;
run;
%mend post;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 656 views
  • 2 likes
  • 4 in conversation