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

Posted on 2011-05-05
Medium Priority
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

Accepted Solution

bradanelson earned 100 total points
ID: 35700301
Assuming the header observation is the 1st row, you use this:

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

Assisted Solution

d507201 earned 100 total points
ID: 35700852
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.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
Suggested Courses

807 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