Write and run SAS programs in your web browser

Save the program in a SOURCE entry in the SAS catalog

Reply
Occasional Contributor
Posts: 17

Save the program in a SOURCE entry in the SAS catalog

Hullo

Good people, am doing a tutorial where i need to write a macro program then Save the program in a SOURCE entry in the SAS catalog Sasuser.Mymacs. (You might need to create the Mymacs catalog before you save the SOURCE entry in it.)

my question is how can i create a folder , or wht are the steps to create a folder in a SOURCE entry in the SAS catalog using SAS University Edition, and then how to I save the macro there.

thanks

Super User
Posts: 18,498

Re: Save the program in a SOURCE entry in the SAS catalog

This is what you want:

 

*Define where macros will be stored;
option mstored sasmstore=mymacros;
*Create library myMacros so that it exists;
libname myMacros '/folders/myfolders/';

*Run macro with SOURCE/STORE so it is stored in catalog;
%macro HelloWorld() / store source;
    data _null_;
        put "Hello, World!";
    run;
%mend;


*Retrieve macro code - shows in log;
%copy helloworld / source;

http://stackoverflow.com/questions/39513623/sas-how-do-i-store-a-macro-in-a-catalog

http://analytics.ncsu.edu/sesug/2005/AD07_05.PDF

 

Super User
Posts: 3,171

Re: Save the program in a SOURCE entry in the SAS catalog

SAS catalogs are not easily managed from SAS UE aka SAS Studio. Most SAS users don't store SAS programs in catalogs these days. I suggest you just store it as an external text file.

Super User
Posts: 18,498

Re: Save the program in a SOURCE entry in the SAS catalog

I agree with @SASKiwi. The usual method is to create a link to a folder where the macros are compiled when SAS starts up you can specify the folders in your AutoExec.

 

However, my guess, based on the wording of the question is that this is homework. 

 

Trusted Advisor
Posts: 1,437

Re: Save the program in a SOURCE entry in the SAS catalog

[ Edited ]

I'm using SAS Univerisity Edition too.

I have tried to load a source into a catalog and couldn't find a way to do it.

 

SAS UE is limited and I have the feeling it is not posssible.

 

On unlimited version you can do SAVE AS and save the source from the program editor to a catalog

by defining target as:  <libref>.<cat_name>.<source_name>.SOURCE

Super User
Posts: 18,498

Re: Save the program in a SOURCE entry in the SAS catalog

@Shmuel

The code above was run on SAS UE and worked.

Trusted Advisor
Posts: 1,437

Re: Save the program in a SOURCE entry in the SAS catalog

Reeza, thank you. The use of / options on %macro statement is new for me. 

Occasional Contributor
Posts: 17

Re: Save the program in a SOURCE entry in the SAS catalog

Sure @Reeza it did run and thats because yu stored it Using Stored Compiled Macros , what am trying to do is store Macro Definitions in Catalog SOURCE Entries.
the instructions for windows OS , say yu use the Save As Object window.
Select File > Save As Object. In the Save As Object window, select the Sasuser library.

If the Sasuser.Mymacs catalog does not already exist, you need to create it. You can either select the Create New Catalog icon or right-click the Save As Object window and select New in order to open the New Catalog window.
Enter Mymacs as the name for the new catalog and click OK.

Enter Printit in the Entry Name field. Make sure that the Entry Type is set to SOURCE entry (SOURCE), then click Save.
I HOPE THIS IS A BETTER EXPLANATION.
Super User
Posts: 18,498

Re: Save the program in a SOURCE entry in the SAS catalog

And if you have Base SAS you can do that. SAS Studio doesn't offer that same functionality AFAIK. 

Also, in SAS UE you can't save to SASUSER folder. 

 

You can extract the source code as in the last line, so don't you have the same functionality?

 

 

Super User
Posts: 3,171

Re: Save the program in a SOURCE entry in the SAS catalog

[ Edited ]

To give you some historical context, storing SAS code in SAS catalogs used to be quite common 15 or more years ago when SAS users only had complete SAS installations on their PCs and the SAS Windowing System AKA Display Manager was the dominant interface.

 

Users built complete windowing applications using SAS/AF software with the SCL applications and SAS source code developed stored in SAS catalogs. With the move to thin client interfaces, particularly now web-based ones, use of SAS catalogs for storing applications and code is pretty much obsolete. They are still relevant however for storing SAS formats. This explains why there is no functionality to store SAS code in SAS catalogs in SAS's thin client tools like EG and SAS Studio.

 

PROC CATALOG and DATASETS are really the only ways to interact with SAS catalogs in SAS Studio. You can delete, copy, rename catalog members but you can't save SOURCE entries. PROC FORMAT creates format-type entries like FORMATC, FORMATN etc.   

Trusted Advisor
Posts: 1,437

Re: Save the program in a SOURCE entry in the SAS catalog

[ Edited ]

On SAS UE I succeded to store a macro into a catalog without to predefine it, 

using the method @Reeza mentioned (%macro ... /store source; ) and I could

display it in the log, BUT I could not find a away to copy it into the program editor

in order to edit/update it.

Valued Guide
Posts: 2,175

Re: Save the program in a SOURCE entry in the SAS catalog

Catalogs  make a handy container for modest volumes.

As there is a catalog engine for the filename statement, base SAS (which EG, UE and Studio all use to run SAS) can write syntax to a catalog entry.

I do not have enough experience of Stored Processes or the equivalent forms used by SAS Studio and UE to suggest that route would allow you to create your own process to easily store your own code in a SAS catalog. However, this demo program did work in UE. I included proc catalog code to show the contents of the catalog.  The prerequisite: a file in myfolders/ named "thatprog.sas"

filename there '/folders/myfolders' ;
%let trialcode = thatprog ;
data _null_ ;
filename mycat catalog 'work.demo' lrecl= 256 ;
file mycat("&trialcode..source") ;
infile there("&trialcode..sas") ;
input ;
put _infile_ ;
run ;

proc catalog c= work.demo ;
contents ;
run;
quit ;

I use the code-library filename approach, expecting the code library to be a common definition, and regularly the only extra definition will be the name for "thatprog"

Hope it might be helpful...

 

Ask a Question
Discussion stats
  • 11 replies
  • 711 views
  • 4 likes
  • 5 in conversation