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

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
Oligolas
Barite | Level 11

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 -

View solution in original post

15 REPLIES 15
SASKiwi
PROC Star

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.

gabriel_k
Obsidian | Level 7

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. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.  

gabriel_k
Obsidian | Level 7
There is some macro code, sas base code, it exports and imorts data.. does lots of stuff, the question is how to keep track of final code executed and try to have it in the file to rerun the later in case of problems or something.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Astounding
PROC Star

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.)

Oligolas
Barite | Level 11

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 -

gabriel_k
Obsidian | Level 7
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?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

gabriel_k
Obsidian | Level 7

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:) 

gabriel_k
Obsidian | Level 7

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. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Not sure I follow you.  Could you provide a small example to illustrate your problem.

gabriel_k
Obsidian | Level 7

Never mind, its fine, I'll run first the code that defins variables. 

gabriel_k
Obsidian | Level 7

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?  

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
  • 15 replies
  • 2465 views
  • 2 likes
  • 5 in conversation