BookmarkSubscribeRSS Feed
shreyansh241990
Calcite | Level 5

I have come across a method where we get the sha code when we hit the github url but once i have done the get request and have the tree code as well as the shacode. Once i perform the post operation i am getting 404 as the error can you help regarding this. i have achieved the same using rest api but want to do the same using sas studio program that i have created .

 

%let user="username";
%let pass="personaltoken generated at githu";
filename eqty "/home/mystudiodirectory/test.txt" lrecl=32000;

proc http
  url="https://api.github.com/repos/user/repos/git/refs/heads/master"
  method="GET" out=eqty webusername=&user
  webpassword=&pass
  ct="application/text";
run;

data firstrequest;
  infile "/home/mystudiodirectory0/test.txt" dsd lrecl=3000000;
  input x : $2000. @@;
  retain flag;
  pos=find(x, "sha");
  if(pos>0) then
    do;
      flag=1;
      var=scan(x, 3, '""');
      shalatestcommit=scan(x, 5, '""');
    end;
run;

data request2(keep=shalatestcommit);
  set firstrequest;
  if var not in ('sha') then
    delete;
  call symput('shaltcommit', trim(shalatestcommit));
run;

/*******************************second request**************************/
%let url=https://api.github.com/repos/user/repository/git/commits/&shaltcommit.;
filename eqty1 "/home/mystudiodirectory0/test1.txt" lrecl=32000;

proc http url="&url" method="GET" out=eqty1 webusername=&user
  webpassword=&pass
  ct="application/text";

data secondrequest;
  infile "/home/mystudiodirectory0/test1.txt" dsd lrecl=3000000;
  input x : $2000. @@;
  retain flag1;
  pos=find(x, "tree");
  if(pos>0) then
    do;
      flag1=1;
      var=scan(x, 1, '""');
      treecommit=scan(x, 5, '""');
    end;
run;

data request3(keep=treecommit);
  set secondrequest;
  if var not in ('tree') then
    delete;
  call symput('treecommit', trim(treecommit));
run;

/************************************************************/
*filename eqty3 "/home/mystudiodirectory0/test3.txt";

/*data store;
y=compress(symget(&body));
file eqty3;
put y;
run;*/
filename eqty2 "/home/mystudiodirectory0/test2.txt" lrecl=32000;

data _null_;
  infile datalines;
  file eqty2;
  input;
  put _infile_;
  datalines;
{
"base_tree": "treecommit value",
"tree": [
{
"path": "NewFile1.txt",
"mode": "100644",
"type": "blob",
"content": "This is NewFile1."
}
]
}
;
run;

filename eqty3 "/home/mystudiodirectory0/test3.txt" lrecl=32000;
;

proc http url="https://api.github.com/repos/user/repository/git/trees"
  method="POST" in=eqty2 out=eqty3 webusername=&user
  webpassword=&pass;

data thirdrequest;
  infile "/home/mystudiodirectory0/test3.txt" dsd lrecl=3000000;
  input x : $2000. @@;
  retain flag2;
  pos=find(x, "sha");
  if(pos>0) then
    do;
      flag2=1;
      var=scan(x, 1, '""');
      nwshalatestcommit=scan(x, 3, '""');
    end;
run;

 

5 REPLIES 5
ChrisHemedinger
Community Manager

Before we look at anything else, I want to make you and other readers aware of this - in SAS 9.4 Maint 6, a new set of Git functions were introduced in the SAS programming language. 

 

Read all about them in the doc.  These might make your tasks easier to accomplish with less code.

 

The 404 error is "Not Found", and usually the simplest explanation is that the API call you've made isn't valid.  Your program that you shared has placeholders for "repository" and "user" (assuming you would use your own username and a valid repository name), so check those first.  I assume this is the API you're trying to use?

 

 

 

 

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
shreyansh241990
Calcite | Level 5
Chris i am using my user and repository names but i didnt specify it here just replaced those things here and yes the link that you have shared i am using the same approach but i am getting message not found although the two get request i have done i get the tree code and if i use it in rest client it is working fine.So problem is mainly with post method.Let me know if you need more info
shreyansh241990
Calcite | Level 5
Just to add i am using sas studio as the platform
ChrisHemedinger
Community Manager

The 404 error still indicates that the API, as you're calling it in SAS, doesn't exist -- maybe something is just a little bit off.  If it works in another REST client like Postman or cURL, then it should work in SAS as well.

 

I suggest adding the DEBUG statement to your PROC HTTP call and maybe you'll get more information about what you're sending/receiving.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
ChrisHemedinger
Community Manager

Just to add an update: there are new Git functions in Base SAS, and experimental Git integration directly in SAS Studio.  Read about these updates here: Using built-in Git operations in SAS.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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