使用指针控制在SAS中读取原始数据

时间:2018-03-22 20:44:23

标签: sas raw-data

我理解如何使用指针控件在原始数据中搜索短语,然后将值读入SAS变量。我需要知道如何告诉SAS在遇到特定短语时停止读取原始数据。 例如,在下面的代码中,我想仅在短语开始停止之间读取数据。所以Jelly不应该成为输出的一部分

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 个答案:

答案 0 :(得分:1)

你无法将这些组合成一次通过文件。问题是,@'1'会跳过STOP行,因此您的数据步骤无法看到它。

预处理文件。

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;

您可以根据需要制作逻辑,以检测要包含的源文件的哪些部分。

答案 1 :(得分: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;
相关问题