BookmarkSubscribeRSS Feed
Lavender_Gooms
Calcite | Level 5

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?

3 REPLIES 3
Reeza
Super User

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. 

 

Tom
Super User Tom
Super User

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;
 
ballardw
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 6985 views
  • 0 likes
  • 4 in conversation