使用指针控制在 SAS 中读取原始数据
Reading Raw Data in SAS using pointer control
我了解如何使用指针控制在原始数据中搜索短语,然后将值读入 SAS 变量。我需要知道如何告诉 SAS 在遇到特定短语时停止读取原始数据。
例如,在下面的代码中,我只想读取短语 Start 和 Stop 之间的数据。所以果冻不应该是输出的一部分
data work.two;
input @"1" Name :.;
datalines;
Start 1 Frank 6
1 Joan 2
3 Sui Stop
1 Jelly 4
5 Jose 3
;
run;
您无法真正将它们组合成单次通过文件。问题是 @'1'
将跳过其中包含 STOP
的行,因此您的数据步骤将无法看到它。
Pre-process 文件。
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 :. @@;
run;
您可以根据需要使逻辑来检测要包含的源文件的哪些部分尽可能复杂。
所有名字都是每行左起第二个位置,所以名字可以通过扫描函数得到,如果该行有'Stop'则停止循环。
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;
我了解如何使用指针控制在原始数据中搜索短语,然后将值读入 SAS 变量。我需要知道如何告诉 SAS 在遇到特定短语时停止读取原始数据。 例如,在下面的代码中,我只想读取短语 Start 和 Stop 之间的数据。所以果冻不应该是输出的一部分
data work.two;
input @"1" Name :.;
datalines;
Start 1 Frank 6
1 Joan 2
3 Sui Stop
1 Jelly 4
5 Jose 3
;
run;
您无法真正将它们组合成单次通过文件。问题是 @'1'
将跳过其中包含 STOP
的行,因此您的数据步骤将无法看到它。
Pre-process 文件。
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 :. @@;
run;
您可以根据需要使逻辑来检测要包含的源文件的哪些部分尽可能复杂。
所有名字都是每行左起第二个位置,所以名字可以通过扫描函数得到,如果该行有'Stop'则停止循环。
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;