The Statistical Consulting Group at ATS has created a series of %net tools that ease the process of downloading and using SAS macros and is used for delivering macros from our Useful SAS Macros page. These instructions show how you can make your own site for distributing SAS macros. This system for delivering macros was inspired by Stata and how it has built in commands to facilitate the sharing and delivery of Stata programs over the web, and users of Stata will see the obvious similarities between Stata and the system we have created.
Creating Your Site
Here is a simple example based on a site we have created at https://stats.idre.ucla.edu/stat/sas/samplesite/
First, we have a macro called test.sas. Here is what test.sas looks like
%macro test; put "This is a very simple macro"; %mend;
Associated with this macro, we created a help file called test.hlp which is a simple text file. Here is what test.hlp looks like.
This is the test help file for test.sas
We also have an associated sample data file that accompanies this macro called hsb2.sas7bdat. We want to distribute these files together in a package, so we create a file called test.pkg located in https://stats.idre.ucla.edu/stat/sas/samplesite/ that indicates all of the files contained in this package. The file test.pkg looks like this.
d test. Test Program d Statistical Computing and Consulting d UCLA Office of Academic Computing d f test.sas f test.hlp s hsb2.sas7bdat
The top of test.pkg contains a series of lines that describe the package, each starting with a "d". The contents of the description can be anything, as long as they start with a "d" and a space. Following the description is a list of files. Macros and the help files associated with them start with an "f". When a user runs %net_get( test , https://stats.idre.ucla.edu/stat/sas/samplesite/ ) , the files test.sas and test.hlp will be downloaded to the user’s personal macro folder. We also specify that hsb2.sas7bdat is a supplemental file, indicated by an "s". If the user runs %net_get(test,https://stats.idre.ucla.edu/stat/sas/samplesite/ ), these sample files will not be copied; however if the user runs %net_get(test,https://stats.idre.ucla.edu/stat/sas/samplesite/ , c:mydata ), then the macro will be downloaded and the file hsb2.sas7bdat will be copied to the user’s c:mydata directory.
Although the package test.pkg contained just one macro, your package can contain multiple macros, or even no macros, and it can contain multiple supplemental data files, or no supplemental files.
To summarize, we placed the files test.sas, test.hlp, and hsb2.sas7bdat on our web site at https://stats.idre.ucla.edu/stat/sas/samplesite/ . We then added a package file called test.pkg . Now, a user could type %net_get(test , https://stats.idre.ucla.edu/stat/sas/samplesite/ ) and download the macro and help file. The user could type %net_get( test , https://stats.idre.ucla.edu/stat/sas/samplesite/ , c:mydata ) and also download the supplemental file to the folder c:mydata.
As you create more and more packages, you would probably like users to be able to see a list of all of the packages available at your site, a kind of table of contents. You can create a file called sas.toc that lists all of the packages that are available from your site and that users can view with the %net_list command. The sas.toc file is needed for the %net_list command to work for the users, but is not needed for %net_get (or %net_help) to work properly. Here is the sas.toc file we have located at https://stats.idre.ucla.edu/stat/sas/samplesite/ .
d Welcome to UCLA Academic Technology Services SAS sample site. d For more information about these programs, see d our web page at https://stats.idre.ucla.edu/stat/sas/ d p test This is a simple test program
The format of the sas.toc file is much like a package file. It contains one or more lines describing the site, each starting with a "d". Then, it has a list of the packages found at the site, each starting with a "p". As you can see, the "p" lines start with "p" followed by a space and then the name of the package, and then a space and a description of the package. You can have as many packages in a sas.toc file as you like. Having created this sas.toc file, a user can then type %net_list( https://stats.idre.ucla.edu/stat/sas/samplesite/ ) and then the user would see the description lines followed by the list of packages available.
Adding New Packages to Your Site
Above we showed the steps for creating a site from scratch. Suppose you want to add a new package to your site, called newmacro.sas. These are the steps you would follow:
- Create a help file for the macro (called newmacro.hlp) that is a simple text file describing how to use the macro.
- Create a package file (called newmacro.pkg) that describes the package and lists the files in the package (like the package file shown above).
- Copy newmacro.sas, newmacro.hlp and newmacro.pkg to your web server.
- Update your sas.toc file, adding a "p" line for the newmacro package.
Users could then use %net_list( https://stats.idre.ucla.edu/stat/sas/samplesite/ ) and see that newmacro is now one of the packages located at the site and %net_get(test,https://stats.idre.ucla.edu/stat/sas/samplesite/ ) to download the package.