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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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