DATA Step, Macro, Functions and more

Selecting limited rows

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

Selecting limited rows

Hi,

I have 1000 records data and need to select certain number of rows from the data.

for e.g - I want to extract observation/row no . 5, 21, 58, 84, 134, 367, 412, 498, 578, 634.........

Please suggest.


Accepted Solutions
Solution
‎09-05-2017 05:34 AM
Occasional Contributor
Posts: 19

Re: Selecting limited rows

Generate a data set with 1000 numbers.

Data Random_data;

  do num = 1 to 1000;

  OUTPUT;

  end;

RUN;

Use POINT= option to read only those records from the above data set - Random_data;

Data random;

  do i= 5, 21, 58, 84, 134, 367, 412, 498, 578, 634;

  SET Random_data POINT=i;

  OUTPUT;

  end;

  STOP;

RUN;

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Selecting limited rows

data want;

     set have;

     if _n_ in (5,21,58,84,134);

run;

New Contributor
Posts: 3

Re: Selecting limited rows

Hi,

If there is no pattern in the number of rows you want to extract, then you have to conditionally check whether _n_ system variable hold required row numbers. If yes then extract.

If _n_ in (5,21,....);

Solution
‎09-05-2017 05:34 AM
Occasional Contributor
Posts: 19

Re: Selecting limited rows

Generate a data set with 1000 numbers.

Data Random_data;

  do num = 1 to 1000;

  OUTPUT;

  end;

RUN;

Use POINT= option to read only those records from the above data set - Random_data;

Data random;

  do i= 5, 21, 58, 84, 134, 367, 412, 498, 578, 634;

  SET Random_data POINT=i;

  OUTPUT;

  end;

  STOP;

RUN;

Occasional Contributor
Posts: 15

Re: Selecting limited rows

Thank you all for your suggestions.

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 282 views
  • 3 likes
  • 4 in conversation