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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.