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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 972 views
  • 0 likes
  • 2 in conversation