BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Nasser_DRMCP
Lapis Lazuli | Level 10

Hello,

my problem is that the content of the main plog is

"this is the begin of the main prog"

%include "$GRPSBSAS/RQTCP_EI/DEV/include.sas" ;

 

and that s all. I wonder why the main prog does not continue to write "this is the end of the main prog".

I would like to be able to open then to write in a main log.

Then creating and writing in a sub log.

And then, opening again and write again in the main log.

But it seems to me that the proc printto of the include prog also close the main log

Thanks for your help.

 

 

/* below main prog*/
PROC PRINTTO LOG="main.log" NEW; 
RUN;

%put this is the begin of the main prog ;
%include "$GRPSBSAS/RQTCP_EI/DEV/include.sas" ;
%put this is the end of the main prog ;

PROC PRINTTO;
RUN;

/* below an include sub programme*/
PROC PRINTTO LOG="include.log" NEW; 
RUN;

%put this is the begin of the include prog ;
%put this is the end of the include prog ;

PROC PRINTTO;
RUN;
1 ACCEPTED SOLUTION

Accepted Solutions
Nasser_DRMCP
Lapis Lazuli | Level 10

Many Thanks Paige and Erik. Sorry if my description was not so clear !

Thanks to yours answers I get the attended result.

as you can see in the new inserted code, I use this :

PROC PRINTTO LOG="main.log" ; RUN; (without "NEW") to write again in the main.log file

 

The main log contains this text below as I wanted (I added a third included program)

prog include is lauched

prog include is complete

prog include2 is lauched

prog include2 is complete

prog include3 is lauched

prog include3 is complete

PROC PRINTTO LOG="main.log" NEW; RUN;

%put this is the begin of the main prog ;

%put prog include is lauched ;
%include "$GRPSBSAS/RQTCP_EI/DEV/include.sas" ;
PROC PRINTTO LOG="main.log" ; RUN;
%put prog include is completed ;

%put prog include2 is lauched ;
%include "$GRPSBSAS/RQTCP_EI/DEV/include2.sas" ;
PROC PRINTTO LOG="main.log" ; RUN;
%put prog include2 is completed ;

%put prog include3 is lauched ;
%include "$GRPSBSAS/RQTCP_EI/DEV/include3.sas" ;
PROC PRINTTO LOG="main.log" ; RUN;
%put prog include3 is completed ;

%put this is the end of the main prog ;

PROC PRINTTO;
RUN;

Then include.log (or 2 or 3) file contains

"this is the begin of the include prog (or 2 or 3)
this is the end of the include prog(or 2 or 3)

 

 

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

I'm not 100% sure I understand. The part that confuses me is that you have PROC PRINTTO below the main program, I think you would want it above the main program. Similarly, you have PROC PRINTTO LOG="include.log" after the %include, I would think you want it before the %include.

 

I think this would work as you have written it ... but maybe you want the PROC PRINTTO above rather than below as you have written it:

 

/* below main prog*/
PROC PRINTTO LOG="main.log" NEW; 
RUN;

%put this is the begin of the main prog ;
%include "$GRPSBSAS/RQTCP_EI/DEV/include.sas" ;
%put this is the end of the main prog ;

/* below an include sub programme*/
PROC PRINTTO LOG="include.log" NEW; 
RUN;

%put this is the begin of the include prog ;
%put this is the end of the include prog ;

PROC PRINTTO LOG="main.log" ;
RUN;

So the log of your %include gets written to main.log. Then the next items get written to include.log, and anything after that gets written to main.log. But maybe, as I said, you want PROC PRINTTO before rather than after.

 

 

--
Paige Miller
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @Nasser_DRMCP 

 

"it seems to me that the proc printto of the include prog also close the main log".

 

That's what happens, but your description of this behaviour is incorrect, because the included program doesn't have it's own log. Included code is not executed in a side session, it is just copied to the program stack and executed in the main session. The main session has a log that can be redirected to another destination vist Proc Printto log=xxx; statement, until it is "taken back" to the default destination with a Proc Printto; statement. One can't have two log destinations open at the same time.

 

Therefore, you cannnot write to the main log while the log is redirected. It makes no difference if the log is redirected in the main program or in the included code. I wonder what happens with log redirecting if the included code is executed by the Dosubl function and actually runs in a side session. I will try that out later.

Nasser_DRMCP
Lapis Lazuli | Level 10

Many Thanks Paige and Erik. Sorry if my description was not so clear !

Thanks to yours answers I get the attended result.

as you can see in the new inserted code, I use this :

PROC PRINTTO LOG="main.log" ; RUN; (without "NEW") to write again in the main.log file

 

The main log contains this text below as I wanted (I added a third included program)

prog include is lauched

prog include is complete

prog include2 is lauched

prog include2 is complete

prog include3 is lauched

prog include3 is complete

PROC PRINTTO LOG="main.log" NEW; RUN;

%put this is the begin of the main prog ;

%put prog include is lauched ;
%include "$GRPSBSAS/RQTCP_EI/DEV/include.sas" ;
PROC PRINTTO LOG="main.log" ; RUN;
%put prog include is completed ;

%put prog include2 is lauched ;
%include "$GRPSBSAS/RQTCP_EI/DEV/include2.sas" ;
PROC PRINTTO LOG="main.log" ; RUN;
%put prog include2 is completed ;

%put prog include3 is lauched ;
%include "$GRPSBSAS/RQTCP_EI/DEV/include3.sas" ;
PROC PRINTTO LOG="main.log" ; RUN;
%put prog include3 is completed ;

%put this is the end of the main prog ;

PROC PRINTTO;
RUN;

Then include.log (or 2 or 3) file contains

"this is the begin of the include prog (or 2 or 3)
this is the end of the include prog(or 2 or 3)

 

 

Tom
Super User Tom
Super User

So from the solution you posted it looks like the actual problem is that the "subroutines" (the included files) are also using PROC PRINTTO?

 

Or was the request to just write only those start/stop messages to a different file?

If so then why not just do that instead of using PROC PRINTTO so that the actual log messages stay in the actual log?

data _null_;
  file "main.log" ;
  put 'this is the begin of the main prog';
run;

data _null_;
  file "main.log" mod;
  put 'prog include is launched';
run;
%include "$GRPSBSAS/RQTCP_EI/DEV/include.sas" ;
data _null_;
  file "main.log" mod;
  put 'prog include is completed ';
run;
...
data _null_;
  file "main.log" mod;
  put 'this is the end of the main prog';
run;
Nasser_DRMCP
Lapis Lazuli | Level 10

hello

thanks for your answer;

No, the request was not to just write only start/stop messages to a different file. but  this was not specifed in my post. your proposal works well 

thanks

Nasser

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 827 views
  • 0 likes
  • 4 in conversation