Hello,
We have a SAS code executed regulary in our data management department. Programs are pretty large (20000 lines) with lots of parametres. Every time we save logs to external files and I wonder if it is possible also to save interpreted code (all variables evaluated) or the base code once executed to external text file too?
Thanks in advance for your ansvers.
Hi,
the MFILE MPRINT functionality is explained >here<
Edit: maybe turning on these options is sufficient for you:
options mprint mprintnest source source2;
options nomprint nomprintnest nosource nosource2;
%macro test(initial);
proc print data=sashelp.class;where substr(name,1,1) eq "&initial.";run;
%mend test;
%test(A);
%test(J);
options mprint mprintnest source source2;
%macro test(initial);
proc print data=sashelp.class;where substr(name,1,1) eq "&initial.";run;
%mend test;
%test(A);
%test(J);
- Cheers -
Please explain what you mean by interpreted code. Do you mean the code generated by SAS macros or something else? If you are referring to the generated SAS macro code then using the SAS options MPRINT will add this to the SAS log and if you want the resolved SAS macro variable values use SYMBOLGEN.
The SAS "base" code is simply what is stored in your SAS programs, unless you are generating your code by some other means. If this is the case please explain.
I mean the code generated by SAS macros you are wright, and it would be great to have it appart of the log that it is possible to execute this code directly in case I need.
In what sense? You have a program that exports data, therefore that program is stored somewhere as a file, hence you already have this? Or are you using some macro or something to generate code, or are you using proc export or something. Some examples might help.
As @Oligolas provided (note I would add symbolgen in also):
options mlogic mprint symbolgen source source2;
Before the run should put all the required information in the log. However the log itself will not be "executable" like your requirement. I think that would require quite some re-work, having the code you already have, instead of running, creating a text file output which is included at the end of the program. But the question is, why can you not re-run the code you have as apposed to the log? If your code isn't replicable then there is something fundamentally wrong with thr process. The code should run the same with the same inputs and create the same output each time.
You can save the generated code to a file of your choice using the MFILE option. (I believe you need to turn on MPRINT as well to make MFILE effective.)
Hi,
the MFILE MPRINT functionality is explained >here<
Edit: maybe turning on these options is sufficient for you:
options mprint mprintnest source source2;
options nomprint nomprintnest nosource nosource2;
%macro test(initial);
proc print data=sashelp.class;where substr(name,1,1) eq "&initial.";run;
%mend test;
%test(A);
%test(J);
options mprint mprintnest source source2;
%macro test(initial);
proc print data=sashelp.class;where substr(name,1,1) eq "&initial.";run;
%mend test;
%test(A);
%test(J);
- Cheers -
filename mprint "...\mysasfile1.sas"; options mprint mfile; run; options mprint mprintnest source source2; %macro test(initial); proc print data=sashelp.class; where substr(name,1,1) eq "&initial."; run; %mend test; %test(A); %test(J);
Trying to run your code with the parts mentioned in the article, everything goes smooth no errors ... but code is not printed to the file. What could it be?
Works fine for me:
filename mprint "...\mysasfile1.sas"; options mprint mfile mprintnest source source2; %macro test(initial); proc print data=sashelp.class; where substr(name,1,1) eq "&initial."; run; %mend test; %test(A); %test(J);
Make sure your path in the mprint statement exists, you have access to it, and it can overwrite any file there. You should get a log message if it doesnt work.
Probably there was some problem with server I've tried it later and it works fine, that is exectly what I was looking for. thanks a lot:)
Is it possible to make SAS interpret the variables also?
For instance if I have a DATA step the macro variables inside are not interpreted in generated code.
Not sure I follow you. Could you provide a small example to illustrate your problem.
Never mind, its fine, I'll run first the code that defins variables.
Hello,
I have found this article and would like to do exectly they are doing.
http://www.lexjansen.com/pharmasug/2002/proceed/TechTech/tt14.pdf
I have contacted autors but don't have an answer so far. May be you have seen an example of a similar program on the internet?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.