BookmarkSubscribeRSS Feed
Dwayne-Dibbley
Calcite | Level 5

Hi, 

 

I am using the following code to pull a json file from a url :

 

options NOQUOTELENMAX;

filename usage "/folders/myfolders/sasuser.v94/usage.json";

%let AccessKey = reallylongstring;
	
proc http
 url="https://a.url"
 method="GET" out=usage;
 headers 
   "Authorization"="Bearer &AccessKey.";
run;

libname usage json "/folders/myfolders/sasuser.v94/usage.json";

data usage;
 set usage.data;
run;

proc print data=usage noobs;
run;

however now the results are returning more that 1000 results and i need to check for nextLink property somehow?

 

in .net you could use:

 

$usagerest = Invoke-Restmethod -url $usageurl -header $authheaders -method get

while ($null -ne $usageRest.nextLink) {
$usageRest = Invoke-Restmethod -uri $usagerest.nextlink -headers $authheaders -method get
}

is something like this possible with proc http in sas?

 

Thanks

 

 

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

 

Not too sure what your .Net code does, but you can post-process the data any way you want in the data step.

 

Would that help?

 

Dwayne-Dibbley
Calcite | Level 5

Hi,

 

the .net code basically fetches the initial json from the url ( which only returns 1000 rows ), then the last row in the json has a link to the next 1000 rows like:

 

......"}],"nextLink":"https://sameurl/nextpage?sessiontoken.......

 

it then runs another get request with the url from nextLink, and repeats until no more nextLink in the data

 

does that help with the explanation?

 

Thanks

ChrisNZ
Tourmaline | Level 20

> it then runs another get request with the url from nextLink, and repeats until no more nextLink in the data

 

In this case I would probably try to read the file as a simple text file using INFILE with the URL engine and FILEVAR= .

 

You can then update the next file to read using the FILEVAR= option and start over.

 

The tricky bit may be to identify the *last* nextLink call, depending on how the JSON file is built.

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 939 views
  • 0 likes
  • 2 in conversation