My original data set contains 7 records, with one "Newic-890426" containing 5 entries while the other "NEWIC-900120". I intend to randomly select 2 records (Criteria:UNIQUE NEWIC) using the proc survey select method. But i notice it is still possible that SAS picks two (2) of the same NEWIC.
I do NOT intend to remove the duplicates prior to selecting as the sole reason as to why certain NEWICs have multiple records because they have earlier fulfilled certain criteria, thus enabling them to stand a "higher chance" of being selected.
proc surveyselect data=test1 out=test2
method=srs
n=2 NOPRINT;
quit;
Could you elaborate on the number of unique records in the original dataset? You listed 2 unique records and ideally want to randomly select 2 unique records using surveyselect. Is this correct?
Regardless, I think you should look into 'method = pps', which is probability proportion to size, rather than srs. You would need to add an intermediary step to make the records unique, such as proc freq, while keeping their count which would enable them to stand a "higher chance" of being selected.
Here is SAS's explanation of the PPS method:
*I used ID to illustrate the method;
data test1;
input id $3.;
datalines;
012
111
123
456
789
012
111
111
111
;
run;
*Unique ID level with count to be used as the probability of selection;
proc freq data = test1;
tables id / out = test_freq ( keep = id count );
run;
*Random selection with count as the probability of selection of ID;
proc surveyselect data = test_freq out = test2 method = pps n = 2 noprint;
size count;
quit;
Could you elaborate on the number of unique records in the original dataset? You listed 2 unique records and ideally want to randomly select 2 unique records using surveyselect. Is this correct?
Regardless, I think you should look into 'method = pps', which is probability proportion to size, rather than srs. You would need to add an intermediary step to make the records unique, such as proc freq, while keeping their count which would enable them to stand a "higher chance" of being selected.
Here is SAS's explanation of the PPS method:
*I used ID to illustrate the method;
data test1;
input id $3.;
datalines;
012
111
123
456
789
012
111
111
111
;
run;
*Unique ID level with count to be used as the probability of selection;
proc freq data = test1;
tables id / out = test_freq ( keep = id count );
run;
*Random selection with count as the probability of selection of ID;
proc surveyselect data = test_freq out = test2 method = pps n = 2 noprint;
size count;
quit;
The count is the ID frequency output from the proc freq. So, if an ID is in the dataset, then it would have at least a frequency of 1.
Yes, the latter. The 'size count;' is telling SAS that the sampling needs to be done by taking into account this variable which is the frequency of records. This statement needs to be in the procedure if you use 'method=pps'.
If you only want one record for each level of a variable you might try the STRATA statement;
Sort the data by the strata variable and then something like:
proc surveyselect data=have out=want sampsize=1;
strata stratavariablename;
run;
will select one record for each level of the given variable.
You can use any fixed value for sampsize as long as every group of records for a strata has at least that many records.
Yes, that would still work.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.