0

I understand how to use pointer control to search for a phrase in the raw data and then read the value into a SAS variable. I need to know how to tell SAS to stop reading the raw data when it encounters a particular phrase. For example in the below code I want to read the data only between phrases Start and Stop. So the Jelly should not be part of the output

data work.two;
input @"1" Name :$32.;
datalines;
Start 1 Frank 6 
1 Joan 2
3 Sui Stop
1 Jelly 4
5 Jose 3
;
run;

Current Output

Desired Output

2 Answers2

1

You cannot really combine those into a single pass through the file. The problem is that the @'1' will skip past the line with STOP in it so there is no way your data step will see it.

Pre-process the file.

filename copy temp;
data _null_;
  file copy ;
  retain start 0 ;
  input ;
  if index(_infile_,'Start') then start=1;
  if start then put _infile_;
  if index(_infile_,'Stop') then stop;
datalines;
Start 1 Frank 6
1 Joan 2
3 Sui Stop
1 Jelly 4
5 Jose 3
;

data work.two;
  infile copy ;
  input @"1" Name :$32. @@;
run;

You can make the logic to detect what parts of the source file to include as complex as you need.

Tom
  • 47,574
  • 2
  • 16
  • 29
0

All names are the second position from the left of each row, so name could be got by scan function, if there is 'Stop' in the row then stop loop.

data work.two;
input @@;
Name=scan(_infile_,-2);
if indexw(_infile_,'Stop')>0 then stop;
input;
datalines;
Start 1 Frank 6 
1 Joan 2
3 Sui Stop
1 Jelly 4
5 Jose 3
;
run;
Shenglin Chen
  • 4,504
  • 11
  • 11