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.
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;
data want;
set have;
if _n_ in (5,21,58,84,134);
run;
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,....);
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;
Thank you all for your suggestions.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.