How do I remove all but the first row from a SAS data set?

Posted on 2011-05-05
Last Modified: 2013-11-16

I have a sas data set with a header row and a high number of subsequent rows with the same information repeated. To get a specific input for another program I just want to keep the header row and the first data row. How do I do that?

Question by:annkan
    LVL 9

    Accepted Solution

    Assuming the header observation is the 1st row, you use this:

    Data Dataset_New;
      SET Dataset;
      IF _N_<=2;
    LVL 7

    Assisted Solution

    data new; set old(obs=2);

    the set statement OBS= option will read only the first N records into the program data vector and write them to the output data set.  The _n_ <= 2 approach reads all records but outputs only the first two.  This won't be a big deal if your dataset is 'small' but could be an issue if it is 'large'.  Small and large are of course site-specific.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
    Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now