How to correctly use STOPOVER in SAS

64 Views Asked by At

I have written below code

proc import file = "/home/u62799951/sasuser.v94/My_Folder/Data.csv" out = MyData dbms = csv replace;
run;
data MyData;
    length COUNTRY $5;
    stopover;
    input COUNTRY $;
run;

In Data.csv, there is one column called COUNTRY which holds names of different countries. My intention is if Country name has more than 5 letters than there should be an error. And I tried to use STOPOVER in that context.

However above code does not show any error despite there are country name like Malaysia.

Could you please help to get the right code?

2

There are 2 best solutions below

0
On BEST ANSWER

STOPOVER will stop the data step when the line does not have enough characters to satisfy the input. The opposite of what you seem to want.

If you want to test if something has too many characters you will need to write that logic yourself.

data want;
  infile .... truncover ;
  length dummy $20 country $5 ;
  input dummy ;
  if length(dummy) <= 5 then country=dummy;
  else do;  
     put 'ERROR: ' dummy 'is too long a value for country.';
     stop;
  end;
  drop dummy;
 run;
0
On

STOPOVER is an option for the INFILE statement. It is not a stand alone statement. The STOPOVER behavior only occurs if your INPUT statement is trying to read more data from a record than there is available. There is no STOPUNDER. Use a test to check for data too long condition.

data _null_;
  set mydata;
  if length (COUNTRY) > 5 then do;
    put 'ERROR: Stopping due to ' COUNTRY=;
    ABORT CANCEL;
  end;
run;

You could use STOP instead of ABORT CANCEL, but which depends on what you really want done.