Hi,
i have a file that i need to read in and if data in the position 29-31 is not missing then stop or abort the process.
The file has no headers so i am using the code below and after running it i dont see much happening in the logs and i have purposely put data in the position given above. Is this below right? Any one please
data _null_;
infile file;
input @;
if substr(_infile_,29,31) ne'' then stop;
run;
Thx
You will likely get unexpected results with
if substr(_infile_,29,31) ne'' then stop;
As that substr says to start at position 29 and look at the next 31 positions
You intended
if substr(_infile_,29,3) ne'' then stop;
to read a length of 3 characters
The log should tell you how many records were read. If there was something in the first line of the file then the log would show 1 record read. Assuming you had more lines in your file then the count would show the first line with something in that position. So since you say you made sure there was something in the first line then the program stops on the first line.
Note, you could read that position directly:
input test 29-31 @;
if test ne '' then stop
You will likely get unexpected results with
if substr(_infile_,29,31) ne'' then stop;
As that substr says to start at position 29 and look at the next 31 positions
You intended
if substr(_infile_,29,3) ne'' then stop;
to read a length of 3 characters
The log should tell you how many records were read. If there was something in the first line of the file then the log would show 1 record read. Assuming you had more lines in your file then the count would show the first line with something in that position. So since you say you made sure there was something in the first line then the program stops on the first line.
Note, you could read that position directly:
input test 29-31 @;
if test ne '' then stop
Yes you could redirect the result to a different data set.
data good (drop= LongStr test) bad (keep=LongStr); /*<= TWO separate data sets that will have different variables*/
Length LongStr $ 200; /*large enough to hold the longest expected _infile_ result*/
infile file;
length test $ 3.;
input test $ 29-31 @;
If test ne '' then do;
output bad;
input; /* to advance to next record*/
end;
Else do;
Input <your statements to read the data>;
<any other statements>
Output good; /* need to explicitly write to the other set*/
end;
run;
thanks a lot!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.