@Zach84 wrote:
I have a dataset that has variables named Amin to Amax. E.g. A121, A122 up to A314. min and max are created in some procedure before. I would like automatically to do the following
1) to keep variables greater than e.g. A150 i.e. A150, A151, up to A(max(xx)) i.e.
Data newdata;
set olddata;
keep A150-Amax;
run;
2) drop all above e.g. A180 i.e. keep Amin - A180 i.e.
Data newdata;
set olddata;
keep Amin-A180;
run;
Thanks
For variables that have actual numbers as part of the name then: Keep A120 - A180 is fine.
But character values seldom sort properly to include in a list. So if you have an actual name like Amax then including that in a list is likely not going to be greatly helpful. If you don't know what the lowest or largest index is and need to use something like A20 we'll need to add a step to identify that and is likely going to be some additional code involved that may require sharing more about your actual data.
If the variables are sequential in the data then you can use a keep or drop with two dashes when the names are not as nice but are in column order:
A list like: Keep thisvar -- thatvar will keep all of the variables in order.