DATA Step, Macro, Functions and more

How do I skip lines when reading data sets?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 119
Accepted Solution

How do I skip lines when reading data sets?

Hi,

 

I have tried to read other posts but nothing has worked.

This is an example problem for how to do this with much bigger files.

 

Essentially, in this example, I have two files, file a and file b. They were originally raw data .txt files, but I am using SAS Studio Linux and find that I have to convert these to .Sas files to work with them. So, I have file a.sas and file b.sas. Both files have the name (File A, or File B) as the first line, and then have the raw data. I am trying to read data from the two files, while skipping over the File A and File B part. So far, nothing has worked.

 

Here is File_A:

File A
10 20 30
40 50 60
70 80 90

 

Here is File_B

File B
11 21 31
41 51 61
71 81 91

 

 

Here is my attempted code:

---------------------

Libname Learn'/folders/myfolders/Learn' ;

Data Multiple_Files;
    If finished=0 then infile'/folders/myfolders/Learn/File_a.sas' end=finished ;   
    else infile'/folders/myfolders/Learn/file_b.sas' ;
    Input  @1 ;     /*null input to skip over File A and File B
    Input  X Y Z ;  
run ;

----------------------

 

Here is the ouput I am getting. Note that Not only line1, which has File A and Filbe B, but also Line 3 is missing from both data sets.

Why is this, and how can I correct this, so that only line 1 does not appear? Thanks!

 

                 X           Y           Z
1102030
2708090
3112131
4

 71        81           91                           

 


Accepted Solutions
Solution
‎04-04-2018 08:29 PM
Valued Guide
Posts: 555

Re: How do I skip lines when reading data sets?

Posted in reply to ManitobaMoose

Just use a normal input statement without the @1 but add the firstobs=2 option to your infile statement http://documentation.sas.com/?docsetId=lestmtsref&docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&docs...

View solution in original post


All Replies
Solution
‎04-04-2018 08:29 PM
Valued Guide
Posts: 555

Re: How do I skip lines when reading data sets?

Posted in reply to ManitobaMoose

Just use a normal input statement without the @1 but add the firstobs=2 option to your infile statement http://documentation.sas.com/?docsetId=lestmtsref&docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&docs...

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 87 views
  • 0 likes
  • 2 in conversation