Macro help!!!!!

Reply
New Contributor
Posts: 3

Macro help!!!!!

Help..

I am running the program below.  I am trying to get it to read every vin within the S dataset and send back all the information related to each VIN.  However my program is reading all !!the vins in the data table S yet it is only sending back output from the last vin it reads.  How can I get it to send me information on all the VINS located in the data set?  What am I missing to make this run correctly?

options symbolgen mprint;

filename response "/abc/default/PONSE.txt";

filename abc "/abc/headerOut.txt";

filename headerin "/abc/default/def.txt";

proc sql;

   create table s as

   select i.vin, c.dealer_id

      from inventory i, customer c

    where i.customer_skey = c.customer_skey

    and i.flag = 1

    and a_dealer_id is not null;

run;

proc sql;

    select distinct vin into:vins separated by '","' from s;

quit;

%PUT &VINS;

%macro CreateString;

%LET N=1;

%LET THISVIN=%UPCASE(%SCAN(&VINS,&N,%STR( )));/*Parse the first VIN in the input string delimited by spaces.*/

%DO %WHILE (%LENGTH(&THISVIN)>0);/*For each VIN in the space-delimited input string...*/

  %IF &N = 1 %THEN %LET VINSQUOTES= "&THISVIN";/*Assign the first VIN enclosed in quotes to a macro variable*/

  %ELSE %LET VINSQUOTES=&VINSQUOTES, "&THISVIN";/*Append the next quote enclosed VIN to the string*/

  %LET N=%EVAL(&N+1);/*Increment the variable counter.*/

  %LET THISVIN=%SCAN(&VINS,&N,%STR( ));/*Parse the next VIN in the input string delimited by spaces.*/

%let abc="https://point.com/ro/&vins.";

proc http java_http

          out=response

          headerin=headerin

   headerout=abc

          url="&abc."

          method='GET'

   ct="application/json"

run;

%END;

%PUT &VINSQUOTES;

%mend;

%CreateString;

Super User
Super User
Posts: 6,318

Re: Macro help!!!!!

Why are you building the list using comma as the delimiter and then scanning it using space as the delimiter?

New Contributor
Posts: 3

Re: Macro help!!!!!

That was a error not changed by me.  It should be scanned for commas.

Esteemed Advisor
Esteemed Advisor
Posts: 7,203

Re: Macro help!!!!!

Sorry, I do not follow the code, or the necessity for this approach.  Please start by providing some test data, in the form of a datastep, and required output.

That whole create string macro can be removed and replaced with simple data _null_; call execute block:

options symbolgen mprint;

filename response "/abc/default/PONSE.txt";

filename abc "/abc/headerOut.txt";

filename headerin "/abc/default/def.txt";

proc sql;

   create table s as

   select i.vin, c.dealer_id

      from inventory i, customer c

    where i.customer_skey = c.customer_skey

    and i.flag = 1

    and a_dealer_id is not null;

run;

data _null_;

     set s;

     call execute('proc http java_http out=response headerin=headerin headerout=abc url="&abc. method='GET'ct="application/json"; run;');

run;

update the above call execute to what you need to include from the s dataset. 

Super User
Super User
Posts: 6,318

Re: Macro help!!!!!

You are looping over a list and then inside the loop using PROC HTTP to generate the same OUT= dataset over and over.

That is why you only see the last one.

Perhaps you just need to add this after the PROC HTTP step.

proc append base=all_responses data=response force;

run;

Ask a Question
Discussion stats
  • 4 replies
  • 268 views
  • 0 likes
  • 3 in conversation