BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JSWilson64
Fluorite | Level 6

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

8 REPLIES 8
SASKiwi
PROC Star

The FILENAME statement can help you here:

 

http://support.sas.com/documentation/cdl/en/lestmtsref/68024/HTML/default/viewer.htm#n0e720f80cp61wn...

 

You can then use %include or from your command line INCLUDE fileref to bring the source code into the SAS editor.

JSWilson64
Fluorite | Level 6

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!

SASKiwi
PROC Star

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)';
Reeza
Super User

%COPY?

 

http://support.sas.com/documentation/cdl/en/mcrolref/67912/HTML/default/viewer.htm#p0oltlodtnemugn10...

 

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. 

Tom
Super User Tom
Super User

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;
JSWilson64
Fluorite | Level 6

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.

Tom
Super User Tom
Super User

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 ;

   

Ksharp
Super User

data pgm=stored.sample;
describe;
run;

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!

How to Concatenate Values

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.

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
  • 8 replies
  • 2009 views
  • 0 likes
  • 5 in conversation