Minor suggestion. When providing example data it is a good idea that other than a key variable, such as your year, has different values so you can see in the result what happens.
Then actually show some example(s) of desired result.
Another way:
data xxx;
input YEAR data;
/* to get different values of data for later examination*/
data= data+ _n_;
datalines;
2001 123
2002 123
2001 123
2003 123
2001 123
2003 123
2004 123
2005 123
2001 123
2003 123
;
proc sql;
create table years as
select distinct year
from xxx
order by year;
run;
proc surveyselect data=years out=selectedyears noprint
sampsize=2;
run;
proc sql;
create table onerandomsample as
select b.*
from selectedyears as a
inner join
xxx as b
on a.year=b.year
;
quit;
If you want to keep the generated random sample you would change the name of "onerandomsample" each time you do this process.
You would change the number of sampled years by changing SAMPSIZE in the Proc surveyselect. There is some additional information that could be generated by Surveyselect such as sampling weights if needed. There is also an option SELECTALL for Surveyselect in case you ask for more years of data than exist in your base data that will result in all the data selected.
... View more