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
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_.
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_.
While you already have the correct answer, but as they always say, SAS has 6 solutions for every problem
,
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
Thank you so so much both!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.