I have a .lst file that contain information similar to what’s below.
I want to keep the number next to the word LABEL.
For example:
Varname len1 len2 l abel ndif maxdif
Aaaa 1 1 LABEL 4 .01
BBBB 2 2 LABEL 5 0.2
I want to keep only
AAAA 4
BBBB 5
I should I do this in SAS?
Read the file into a dataset, then use a keep statement to keep the variables you want.
filename test "c:\art\test.lst";
/*create .lst file*/
data _null_;
file test;
input;
put _infile_;
cards;
Varname len1 len2 l abel ndif maxdif
Aaaa 1 1 LABEL 4 .01
BBBB 2 2 LABEL 5 0.2
;
data want;
infile test firstobs=2;
input varname $@;
input @"LABEL" ndif;
run;
That was super slick, Art. I know your solution is probably close to what OP want, but here is a trick from using Parmcards to make a stream-in data flow:
filename ft15f001 temp;
data _null_;
input;
parmcards;
Varname len1 len2 l abel ndif maxdif
Aaaa 1 1 LABEL 4 .01
BBBB 2 2 LABEL 5 0.2
;
data want;
infile ft15f001 firstobs=2;
input varname $@;
input @"LABEL" ndif;
run;
Haikuo
Haikuo:
When I run your code I get an error: No DATALINES or INFILE statement. But If I remove the input statement in the data _null_ step I get the same result without the error message.
you are correct. It runs through even without data _null_;
filename ft15f001 temp;
parmcards;
Varname len1 len2 l abel ndif maxdif
Aaaa 1 1 LABEL 4 .01
BBBB 2 2 LABEL 5 0.2
;
data want3;
infile ft15f001 firstobs=2;
input varname $@;
input @"LABEL" ndif;
run;
Haikuo
Possible thought: That looks like the output from proc compare, you can capture that using ODS statements and parse as well, instead of reading in the LST files.
Reeza, you'r right it is result from proc compare. I have used ODS feature to capture the result into a dataset. However, I’m having problem parsing the data because of SAs limitation to put each variable into its own variable. SAS created two variable (batch and type) and if the ndif is longer than 6 digits it puts len2 with ndif.
If you only want the NDIF then use the outstats table filtered, and you can even filter out for only ones that are not equal to 0, though I haven't done that below.
SAS 9.3 :
data class;
set sashelp.class;
if age=14 then weight=0;
run;
proc compare data=sashelp.class compare=class outstats=check (where=(_type_="NDIF"));
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.