BookmarkSubscribeRSS Feed
Aexor
Pyrite | Level 9

Hi All,

I am new for API calls , wanted to understand how can I create a table

I have table like this

 

table abc
id market_id
1    100
2   500
4   600
3   300
5   400

I have one more table xyz table, in a different database , where we can do only API call to get data.

 

table xyz
market_id   market_cd
100    12
500    13
300   22
600   55
700   44

 

I am doing API call like this to get market_cd.

proc sql noprint;
select market_id into :mkt_typ_id
from abc
where id in ('100');
quit;
%put &mkt_typ_id;

proc http
url="&SERVICESBASEURL./&mkt_typ_id"
method="GET"
out=resp2
OAUTH_BEARER = SAS_SERVICES;
run;
libname resp2 json fileref=resp2;

proc sql noprint;
select trim(code) into: market_cd from resp2.root
where lowcase(memberId)= "&mkt_typ_id";
quit;
%put &market_cd;

-- here I am getting only one value for market_cd that is 12.

But I want to create a table like table three as mentioned below.

 

table three
id  market_cd
1    12
2    13
4   55
3   22

Can anyone please help , How to achieve this.

2 REPLIES 2
HB
Barite | Level 11 HB
Barite | Level 11

Your initial select 

 

select market_id into :mkt_typ_id
from abc
where id in ('100');

 

only selects one record. 

 

So I assume your API call only matches one record.

 

Try deleting the WHERE clause. 

Tom
Super User Tom
Super User

I don't understand.

Is the issue that each API call can only return one value?

Or is the issue that last SQL step that is only pulling one value from the JSON response that the API returned?

If the later then don't use a macro variable to get the data from the JSON file. Just use normal SAS code instead.

 

If the former then you just need to do it one at a time.  You can use PROC APPEND or the PROC SQL INSERT statement to append the results into one dataset.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 119 views
  • 0 likes
  • 3 in conversation