01-23-2013 11:22 AM
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.
/* 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));
%IF %SYSFUNC(exist(%UPCASE(&Nm))) %THEN %DO;
%PUT Change &FileName to &FileNameMMYY;
CHANGE &FileName= &FileNameMMYY;
%PUT ******* &DataLibrary.&FileName does not exists. *******;
01-23-2013 01:58 PM
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
01-24-2013 08:50 AM
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;
I run the program and then check the syserr in a seperate macro called %chkerr
This has fixed my issue.