1

I wanna append string to a text file at beginning and end of proc sql statment, I tried like below

libname DXZ 'libpath';
%macro processlogger(msg);
filename logfile '../Processlog/processlog.txt';
data _null_;
file logfile; 
put "%superq(message)";
run;
%mend;

%processlogger ('Begin');
proc sql;
    select * from DZ.NoofDaysin_Reje /* Mispelled name */
    run;

%processlogger('End');

I seems to messing up in macro variable, is there any other way I can do this, Thanks

1
  • What is messing up? Are you getting SAS errors? Wrong output? Commented Mar 15, 2018 at 5:02

2 Answers 2

3

If you want to use a data step to append to a text file then you need to add the MOD keyword to the FILE statement.

If you want to print the value of a macro variable that might have quotes and other strange characters in a data step then it is probably best to use symget() to retrieve the value into a datastep variable and print that.

Make sure to reference the macro variable that you created msg and not some other macro variable message.

If you don't want quotes to be included in the value of a macro variable then do not add them.

%macro processlogger(msg);
data _null_;
  file '../Processlog/processlog.txt' mod; 
  length message $32767 ;
  message=symget('msg');
  put message ;
run;
%mend;

%processlogger(Starting at %sysfunc(datetime(),datetime24.3));
%processlogger(Ending at %sysfunc(datetime(),datetime24.3));
Sign up to request clarification or add additional context in comments.

Comments

1

You can also use PRINTTO to redirect your log to a text file. And you have the option to either append to the original file or replace. Example here.

/*Redirect your log file*/
proc printto log='../Processlog/processlog.txt';
   run;
/* Your Code Here */
/* Reset log path to default */
proc printto;
run;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.