BookmarkSubscribeRSS Feed
Muwanguzi
Obsidian | Level 7

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

11 REPLIES 11
Reeza
Super User

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

 

SASKiwi
PROC Star

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.

Reeza
Super User

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. 

 

Shmuel
Garnet | Level 18

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

Reeza
Super User

@Shmuel

The code above was run on SAS UE and worked.

Shmuel
Garnet | Level 18

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

Muwanguzi
Obsidian | Level 7
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.
Reeza
Super User

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?

 

 

SASKiwi
PROC Star

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.   

Shmuel
Garnet | Level 18

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.

Peter_C
Rhodochrosite | Level 12

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...

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 3272 views
  • 9 likes
  • 5 in conversation