keeping first 5 rows of the data

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 102
Accepted Solution

keeping first 5 rows of the data

    i want o keep first 5 lines of the data and delete everything else. how may i do so using the data want; set have; run; ?

many thanks,

aaron


Accepted Solutions
Solution
‎02-24-2015 09:24 AM
Frequent Contributor
Posts: 144

Re: keeping fist 5 rows of the data

Hi Aaron,

you can use the _N_ variable. This variable is the row nuber that appears at the left in the dataset visualisation. To keep the first 5 only must do

data want;

set have;

if _N_<=5;

run;

Keep in mind that a where doesn't work with _N_.

View solution in original post


All Replies
Solution
‎02-24-2015 09:24 AM
Frequent Contributor
Posts: 144

Re: keeping fist 5 rows of the data

Hi Aaron,

you can use the _N_ variable. This variable is the row nuber that appears at the left in the dataset visualisation. To keep the first 5 only must do

data want;

set have;

if _N_<=5;

run;

Keep in mind that a where doesn't work with _N_.

Respected Advisor
Posts: 3,124

Re: keeping fist 5 rows of the data

While you already have the correct answer, but as they always say, SAS has 6 solutions for every problem Smiley Happy,

To avoid read in all of the data, you could do:

1. Stop reading when it is time,

Date want;

set have;

if _n_ >5 then stop;

run;

2. Just bring in 5:

Date want;

set have (obs=5);

run;

Good luck with your homework,

Haikuo

Frequent Contributor
Posts: 102

Re: keeping fist 5 rows of the data

Thank you so so much both!

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 235 views
  • 3 likes
  • 3 in conversation