DATA Step, Macro, Functions and more

What' the point of setting_EFIERR_ macro variable if it isn't used in the code?

Reply
Learner
Posts: 1

What' the point of setting_EFIERR_ macro variable if it isn't used in the code?

[ Edited ]

I'm working on SAS 9.4 for Windows, looking at code similar to that below (though this has obviously been truncated):

 

    data People;
        %let _EFIERR_ = 0;
        infile 'C:\Users\Me\Desktop\People.txt' delimiter='|' MISSOVER DSD lrecl=32767 firstobs=2;
                informat
                name $20.

                format
                name $20.

                Input 
                name $

    if _Error_ then call symputx('EFIERR_',1);
    run;

 

Now to me, this basically says we are going to read in a text file and if there is an error then we'll set the macro variable _EFIERR_ to 1. But why? This appears to be the end of the code so what's the point? Does it attach itself to the resulting table some how?

I've read some stuff and it seems as though _EFIERR_ is an actual global SAS variable so by doing this we are indicating an error has occurred. But I don't see why we need to set this to 1 in this code without doing anything with the variable.

 

Also, does this variable get set to 1 if an error occurred at any point? Or is this variable "attached" or associated with each observation, and thus shows which observations had an error because their _EFIERR_ value will be 1?

Super User
Posts: 23,683

Re: What' the point of setting_EFIERR_ macro variable if it isn't used in the code?

Posted in reply to Lavender_Gooms

This looks like code that's generated by default when you use PROC IMPORT. 

Someone has taken the code and modified it, but has not removed those sections. 

 

PROC IMPORT creates those variables by default so a user can automatically drive the process, but if you're not using it, then you don't need it and can remove it. 

 

Super User
Super User
Posts: 8,075

Re: What' the point of setting_EFIERR_ macro variable if it isn't used in the code?

Posted in reply to Lavender_Gooms

That looks like the code that PROC IMPORT generates. The macro variable is created to indicate there was an error in the execution of the data step, which I assume that PROC IMPORT uses to report back the failure.  Normally you do not need it.  

 

You do not need to use the code as generated by PROC IMPORT as it usually both over complicated and miss uses INFORMAT as if it was intended to define a variable. Normally you would want to use TRUNCOVER instead of MISSOVER to avoid risk of eliminating values that are shorter than expected.  Also there is no need to attach $xx INFORMAT or a FORMAT to character variables, SAS already knows how to read and write character variables.  You should instead use the LENGTH (or ATTRIB) statement to define your variables.  You can add INFORMAT or FORMAT if they are needed, for example for DATE or TIME variables.

data people;
  infile 'C:\Users\Me\Desktop\People.txt' dsd dlm='|' truncover firstobs=2;
  length name $20 ;
  input name ;
run;
 
Super User
Posts: 13,508

Re: What' the point of setting_EFIERR_ macro variable if it isn't used in the code?

Posted in reply to Lavender_Gooms

The variable _error_ when created by some error in a data step is a temporary variable and not available after the end of the data step.

The code sets the macro variable so that if you desire you can test the value of &EFIERR and do something with the information such as run different code or write a specific (additional likely) message to the log.

A value of 1 would tell you that some unspecied error occured though most of the ones in a data step that only reads data would typically generate a warning or error in the log about invalid data.

Ask a Question
Discussion stats
  • 3 replies
  • 136 views
  • 0 likes
  • 4 in conversation