BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
bmutell
Calcite | Level 5

Hello,

 

I'm wondering if it is possible to write specific lines of a SAS program to a file from that same SAS program and, if so, how to go about that.

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
xxformat_com
Barite | Level 11

Hi,

Your request is pretty old but this might help some other reader.

Did you mean something like this, where the content of the macro is saved in another file?


%macro demo (memname=);
%put Message in the log;*won't appear in the new file;
title 'This is a demo';
proc print data=sashelp.&memname.;
run;
%mend demo;


options mfile mprint ;
filename mprint "&xxproject./pgms/new.sas ";
%demo(memname=class);

View solution in original post

9 REPLIES 9
Reeza
Super User
Do you want to generate code based on some data or dynamically and run that or have your code saved to a specific file with a command?

The first is easy, the second I have no idea.
bmutell
Calcite | Level 5

It's the latter of those two options. I want to save a macro definition to a file that I can later %INCLUDE into other SAS programs:

 

 

%macro prnt(var,sum);
   proc print data=srhigh;
      var &var;
      sum ∑
   run;
%mend prnt;

*code to save lines 1-16 to my_macro.sas to C:\Users\me\desktop\;

 

 

Reeza
Super User
I'm trying to understand the logic here, any reason to not just CTRL+S and save the macro? Is the macro code generated somehow? Or just trying to find a full command line interface method?
34reqrwe
Quartz | Level 8

I think you might theoretically be able to do what you are asking (by reading in the sas program via a datastep and creating another sas program as the output) . But I dont think you should.

 

If you want a macro to be available to other SAS Programs you should save the macro in an autocall library.

PaigeMiller
Diamond | Level 26

I'm looking for a bit more explanation.

 

In particular, the words "saved to a file from that same SAS program" don't have an obvious meaning to me.

--
Paige Miller
bmutell
Calcite | Level 5

Please see my reply to Reeza above for further explanation.

PaigeMiller
Diamond | Level 26

So, let me see if this is what you want. You want a program to browse through your code, and pick out the SAS macro(s), and then save them one-by-one into files on your hard disk or network somewhere, so each can be used via %include in other programs. Is that right?

 

I'm not aware of any tool that does this.

--
Paige Miller
MSamaniego
Calcite | Level 5

Have you tried writing your program to read in the SAS log (save to a named file) and parse the text?  You would need to set "OPTIONS MLOGIC SYMBOLGEN" to capture verbose macro output to log.

 

 

xxformat_com
Barite | Level 11

Hi,

Your request is pretty old but this might help some other reader.

Did you mean something like this, where the content of the macro is saved in another file?


%macro demo (memname=);
%put Message in the log;*won't appear in the new file;
title 'This is a demo';
proc print data=sashelp.&memname.;
run;
%mend demo;


options mfile mprint ;
filename mprint "&xxproject./pgms/new.sas ";
%demo(memname=class);

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 9 replies
  • 2763 views
  • 0 likes
  • 6 in conversation