09-21-2016 03:37 PM
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.
09-21-2016 04:34 PM
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;
09-21-2016 04:35 PM
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.
09-21-2016 04:39 PM
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.
09-21-2016 04:52 PM - edited 09-21-2016 04:55 PM
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
09-21-2016 06:05 PM
09-21-2016 06:23 PM
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?
09-24-2016 07:40 PM - edited 09-24-2016 07:42 PM
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.
09-24-2016 08:50 PM - edited 09-24-2016 08:52 PM
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.
02-08-2017 07:06 AM
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") ;
put _infile_ ;
proc catalog c= work.demo ;
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...