BookmarkSubscribeRSS Feed
zqkal
Obsidian | Level 7

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?

9 REPLIES 9
Fugue
Quartz | Level 8

Read the file into a dataset, then use a keep statement to keep the variables you want.

art297
Opal | Level 21

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;

Haikuo
Onyx | Level 15

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

CTorres
Quartz | Level 8

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.

Haikuo
Onyx | Level 15

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

Reeza
Super User

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.

art297
Opal | Level 21

: The one thing you didn't criticize me for, but should have, is that my proposed code could be simplified to just:

data want;

  infile "c:\art\test.lst" firstobs=2;

  input varname $ @"LABEL" ndif;

run;

zqkal
Obsidian | Level 7

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. 

Reeza
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 1957 views
  • 4 likes
  • 6 in conversation