Can foreach be used to keep a group of observations of a specific variable?

I need to keep a group of around 1000 individuals within dataset (eg id=1 id=2.....id=1000) and was trying to work out the most efficient way of doing this.

A search has brought up the "inlist" command but it looks like only 10 or so observations can be listed at a time, and each one needs to be typed out (rather than just id=1 - id=1000)

Any solutions to this would be greatly appreciated, thank you in advance