SAS SYSMSG() inside a SYMPUT/SYMPUTX inside a data _null_

26 Views Asked by At

I am using SAS to loop through a list and perform multiple file move operations. I am performing the move within a data null. if have a in if/then/do when rc ne 0, then an else/do if it's successful. The move operation is working just fine. However, I want to pass error messages back to a macro variable so I can then use a proc sql ; update... to record the message that applies to the specific file where the move failed & then research the errors.

The move operation is working fine. However, I'm having trouble passing sysmsg() into a macro variable.

I've tried the following:

  • symput/symputx("mvar",sysmsg())
  • symput("mvar",%sysfunc(sysmsg())
  • %let mvar=%sysfunc(sysmsg())
  • msg = sysmsg() ; symput("mvar",msg)

None of them seems to be populating the variable with the desired sysmsg() text. what do I need to do?

Is the problem possibly inherent to the loop rather than the symput()/sysmsg() functionality?

2

There are 2 best solutions below

0
data _null_ On

This works.

48         %let msg=;
49         data _null_;
50            rx = fileexist('dummy');
51            call symputx('msg',sysmsg());
52            run;
53         %put NOTE: &=MSG;
NOTE: MSG=WARNING: Physical file does not exist, E:\SASConfig\Lev1\SASApp\dummy.

However, I think it is best to capture the message in the next statement.

48         data _null_;
49            length msg $200;
50            rx = fileexist('dummy'); msg=sysmsg();
51            put msg;
52            call symputx('msg',msg);
53            run;
WARNING: Physical file does not exist, E:\SASConfig\Lev1\SASApp\dummy.
54         %put NOTE: &=MSG;
NOTE: MSG=WARNING: Physical file does not exist, E:\SASConfig\Lev1\SASApp\dummy.

Also there could be no message. When the file exists.

0
Richard On

You can try

proc sql;
  create table messages (message char(200)) ;
  insert into messages values ("%qsysfunc(sysmsg())") ;

or

data message ;
  message = sysmsg() ;
run ;
proc append base=messages data=message ;
run ;