I'm using Proc SurveySelect to select a simple random sample (Method=SRS) for each hospital. The sample size required is 25 or all (if 25 not available). The code works if there are at least 25 records in the pool for selection. It fails if there are fewer than 25 records. I've tried changing to Method=PPS, but I can't get the syntax right. Below is the code I'm currently using.
Any help is appreaciated.
I'm not using a strata statement because this is part of
a macro (see below). I loop through the macro once for each hospital. It works great if the hospital has enough patients to select the full random sample. If I need 25, but there are only 21 patients to select, then the code fails.
I need something that allows me the request 25 or all available.
%put after test numobs= &numobs sampsize= &sampsize;
*** new code stops;
proc surveyselect data=HMASelect
The dictionary.tables file is available to your SAS session as a tool for you to collect information about your datasets. So, the NOBS variable in dictionary.tables will contain the number of observations and the INTO puts the value of NOBS into a macro variable called &numobs. (BTW, the library names and member names in dictionary.tables are stored in all caps...so the WHERE clause will not work if you used lowercase or mixed case.)
Then, you can compare &numobs (the internally constructed macro variable) to &sampsize (the macro variable that you pass in) and do the adjustment accordingly.
Thanks for the second method to solve this problem. I tested and did get the second macro variable containing the number of records in the dataset. I would need to compare the two values and make sure the lowest value is used by the Proc Survey.
I've never seen a macro variable created in a Proc SQL.
Thanks for the insight.