BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
USP2405
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
KrisNori
Obsidian | Level 7

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

4 REPLIES 4
ballardw
Super User

data want;

     set have;

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

run;

Narasimha_Kulkarni33
Calcite | Level 5

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,....);

KrisNori
Obsidian | Level 7

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;

USP2405
Obsidian | Level 7

Thank you all for your suggestions.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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