Jedi SAS Tricks: GIT my macros

This post was kindly contributed by SAS Users - go there to comment and to read the full post.

I use macros extensively in my SAS programs, and over the years have accumulated a few that I find quite useful. The integration of GIT and SAS Studio has made it easy to build a re-usable macro library, so I’ve put some of the more polished macros I’ve written in a GIT repository to share. You can generate a list of the macro files available with this bit of SAS code (which leverages one of those macros)

%let thisMacro=listrepofiles;
filename mcode temp;
proc http url="https://raw.githubusercontent.com/SASJedi/sas-macros/master/%qlowcase(&thisMacro).sas"
          out=mcode;
run;
%include mcode /source2;
filename mcode;
%&thismacro(?)

Running that program makes the listRepoFIles macro available in your SAS session and provides syntax help in the LOG:

NOTE:  *LISTREPOFILES Documentation *******************************

       SYNTAX: %LISTREPOFILES(user,repo,branch,extension)
          user = Username for repo owner (Case sensitive)
          repo = Repo name (Case sensitive)
          branch = branch (Optional, default is master)
          extension = file extension (Optional, default gets all)

       Examples:
       Retrieve a list of all files in the master branch of
       SASJedi repo named sas-macros:
       %LISTREPOFILES(SASJedi,sas-macros)

       Retrieve a list of SAS files in the master branch of
       SASJedi repo named sas-macros:
       %LISTREPOFILES(SASJedi,sas-macros,,sas)

       *************************************************************

NOTE:  Use %LISTREPOFILES(?) for help.

Submitting the code copied straight from the last example in macro documentation:

%LISTREPOFILES(SASJedi,sas-macros,,sas)

will get you a list of the macro source files currently stored in the repository. I’ll share a few here:

List of sas files in the sas-macros repository master branch
Obs path size url
1 benchmark.sas 6255 https://api.github.com/repos/SASJedi/sas-macros/git/blobs/3c6fe9cc8db1264f5e1b6978298ac25e970488ea
2 benchmarkparse.sas 30872 https://api.github.com/repos/SASJedi/sas-macros/git/blobs/0fe16b5de7ce187715bf91ae48e6b0f1ab7b3e0e
3 benchmarkreport.sas 7047 https://api.github.com/repos/SASJedi/sas-macros/git/blobs/e7e75e0ab6c8eacf8ad918680823dc7cd64c2210
4 charcollength.sas 1068 https://api.github.com/repos/SASJedi/sas-macros/git/blobs/fd48d0a1aeefd3b10e705977c61cb7cd1efb7a2e
5 charcollengths.sas 1130 https://api.github.com/repos/SASJedi/sas-macros/git/blobs/4738b57753d4b2af8f34f579a8322598c3d0b6f3
6 data2datastep.sas 4756 https://api.github.com/repos/SASJedi/sas-macros/git/blobs/a1708f9231305306c7a2c517cb665ca546999728

Can you download and get syntax help for the DATA2DATASTEP macro by modifying the very first program in this post? I’ll post my solution for that in the comment section in a few days – but don’t peek right away! Why not try it yourself first? 

May the SAS be with you!
Mark

Jedi SAS Tricks: GIT my macros was published on SAS Users.

This post was kindly contributed by SAS Users - go there to comment and to read the full post.