I have "inherited" as SAS catalog that contains several dozen program elements. I need to pull the elements out into individual SAS program files. Seems like a simple task... I just can't seem to figure out how to do it. 🙂
Using desktop SAS on Windows 7, if that matters.
Edit:
What I'm hoping to be able to do is get the names of the program elements in the catalog (I know how to do this) and write a SAS program that will take each program element and output it as a SAS program file.
So something like MyLib.Mycat.MyProgram1.Source becomes d:\MyFolder\Myprogram1.sas
I'd rather not have to manually save and name each file for referential integrity with other programs that access the catalogs.
Just use a DATA _NULL_ step to copy the lines.
%let memname=fred ;
data _null_;
infile "work.mycat.&memname..source" catalog ;
file "~/test/&memname..sas";
input;
put _infile_;
run;
The FILENAME statement can help you here:
You can then use %include or from your command line INCLUDE fileref to bring the source code into the SAS editor.
I don't know if %include will work, since that submits the code and all I want to do is save it as a ProgramName1.sas file.
I edited my original post with more info on what I'm trying to do. Thanks!
Just use INCLUDE fileref then - that will extract the source program into the SAS editor without running it. From there you can SAVE it.
filename dir catalog 'mylib.mycatalog';
dm 'include dir(prog1)';
%COPY?
This assumes that the source was actually saved in the catalog, and not just the compiled program....if it's just the compiled program you might be out of luck.
Just use a DATA _NULL_ step to copy the lines.
%let memname=fred ;
data _null_;
infile "work.mycat.&memname..source" catalog ;
file "~/test/&memname..sas";
input;
put _infile_;
run;
Thanks, Tom. This worked great, with the least amount of effort on my part. I used the CONTENTS option in Proc Catalog to list out the objects in the catalog, then used Excel to build some repetitive data step statements to save each item out into a SAS program file with the same name.
Excel???????? Why the heck would you use Excel to generate SAS code?
%let catalog=work.mycat ;
%let dir=~/test ;
filename code temp;
data _null_;
set sashelp.vcatalg ;
where libname="%upcase(%scan(&catalog,1,'.'))"
and memname="%upcase(%scan(&catalog,2,'.'))"
and objtype='SOURCE'
;
length catalog fname $200 ;
catalog=catx('.',"&catalog",objname,objtype);
fname = catx('/',"&dir",cats(lowcase(objname),'.sas'));
file code ;
put 'data _null_;'
/ ' infile ' catalog :$quote. 'catalog;'
/ ' file ' fname :$quote. ';'
/ ' input;'
/ ' put _infile_;'
/ 'run;'
;
run;
%include code ;
data pgm=stored.sample; describe; run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.