DATA Step, Macro, Functions and more

Sas Change fucntion and the SYSERR macro variable

Reply
Contributor
Posts: 20

Sas Change fucntion and the SYSERR macro variable

Hi

I am changing the names of sasdata sets in a sas macro. When the new dataset name already exists the program writes an error message to my log. Which is correct. However I am trying to catch this error within the program using the &SYSERR variable. But this is always 0 after the change statment has been executed. Does running the change statment from within a macro effect the value of the &SYSERR variable. Is there another variable that I could use as this would be very handy for error checking. Code is below.

                 


%macro ChangeFileName;

/*  Change the file name of the existing files. The new file name is built using
  Shared Datasets.File_Names.Archive_File_Name and the postfix returned by the %SetMMYY macro */

  %PUT "------- Change File Names------";
  %DO i=1 %TO &Bkup_NumObs;
   %LET FileName =  %SYSFUNC(CAT(&Bkup_File_Name,&i));
   %LET FileNameMMYY  = %SYSFUNC(CAT(&Bkup_File_Name_MMYY,&i));
   %LET FileNameMMYY = &FileNameMMYY.&MMYY;
  
   %LET Nm = %SYSFUNC(CAT(&DataLibrary,.,&FileName));
   %PUT &Nm;

   %IF %SYSFUNC(exist(%UPCASE(&Nm))) %THEN %DO;
    %PUT Change &FileName to &FileNameMMYY;    
    CHANGE &FileName= &FileNameMMYY;
    %PUT &syserr;
   %END;
   %ELSE %DO;
     %PUT ******* &DataLibrary.&FileName does not exists. *******;
   %END;
  %END;
  run;
%mend 
ChangeFileName;

Super User
Posts: 10,500

Re: Sas Change fucntion and the SYSERR macro variable

You can check for the existence of the data set with the following where &dsn resolves to your data set name.

%if %sysfunc(exist(&dsn)) %then   %do (etc)

Probably putting your Change within another %else

Contributor
Posts: 20

Re: Sas Change fucntion and the SYSERR macro variable

I wrapped my macro call in a program and used %include program-name in placeof the call to the macro.

So for the above code I now have a program called Prog_ChangeFileName. With the code to run the macro.

PROC DATASETS Library=&DataLibrary;

       %ChangeFileName;

QUIT;

I run the program and then check the syserr in a seperate macro called %chkerr

%INCLUDE automation_run_change_file_name;

%chkerr;

This has fixed my issue.

Ask a Question
Discussion stats
  • 2 replies
  • 445 views
  • 0 likes
  • 2 in conversation