Hi Experts,
In my dataset, there are a lot of time series observations for each firm. I would like to keep first 25 observations for each firm. How can I do that?
Try this
data test;
do _N_ = 1 by 1 until (last.stock);
set sashelp.stocks;
by stock;
if _N_ <= 25 then output;
end;
run;
Hi,
The code keeps only one observation for each firm. I wanted to keep 25 observations for each firm.
No. I assume that your data is sorted. Then the 25 first obs for each firm (stock in this case) are outputted
log:
1 data test;
2 do _N_ = 1 by 1 until (last.stock);
3 set sashelp.stocks;
4 by stock;
5 if _N_ <= 25 then output;
6 end;
7 run;
NOTE: There were 699 observations read from the data set SASHELP.STOCKS.
NOTE: The data set WORK.TEST has 75 observations and 8 variables.
NOTE: DATA statement used (Total process time):
real time 0.13 seconds
cpu time 0.04 seconds
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!
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.