<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Random Samples in SAS Health and Life Sciences</title>
    <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2326#M169</link>
    <description>You might also try using the SELECTALL option within the PROC SURVEYSELECT statement.</description>
    <pubDate>Wed, 14 Mar 2007 14:33:10 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2007-03-14T14:33:10Z</dc:date>
    <item>
      <title>Random Samples</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2318#M161</link>
      <description>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.&lt;BR /&gt;
Any help is appreaciated.&lt;BR /&gt;
SheriB&lt;BR /&gt;
&lt;BR /&gt;
proc surveyselect data=HMASelect                   &lt;BR /&gt;
		  n=25;&lt;BR /&gt;
                  method=srs                  &lt;BR /&gt;
                  out=HSW;  &lt;BR /&gt;
run;</description>
      <pubDate>Thu, 15 Feb 2007 21:01:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2318#M161</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-02-15T21:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: Random Samples</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2319#M162</link>
      <description>ISn't there a STRATA statement missing in your program ?&lt;BR /&gt;
I thought that it would look something like&lt;BR /&gt;
&lt;BR /&gt;
PROC SURVEYSELECT DATA = patients N = 25 METHOD = SRS OUT = sample ;&lt;BR /&gt;
   STRATA hospital ; /* provided that the data is already sorted by hospital */&lt;BR /&gt;
RUN ;&lt;BR /&gt;
&lt;BR /&gt;
And be careful, there is way too much semi-colons in your program !</description>
      <pubDate>Mon, 19 Feb 2007 13:39:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2319#M162</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2007-02-19T13:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: Random Samples</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2320#M163</link>
      <description>I'm not using a strata statement because this is part of&lt;BR /&gt;
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.  &lt;BR /&gt;
&lt;BR /&gt;
I need something that allows me the request 25 or all available.&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your input.  I'm really stuck!&lt;BR /&gt;
Sheri &lt;BR /&gt;
&lt;BR /&gt;
%MACRO MSELECT(DSNIN,COMP,DSNOUT,SampSize,Frequency,Title2);&lt;BR /&gt;
&lt;BR /&gt;
data HMASelect (drop=Company);&lt;BR /&gt;
set &amp;amp;DSNIN;&lt;BR /&gt;
if Company="&amp;amp;COMP"; &lt;BR /&gt;
run; &lt;BR /&gt;
  &lt;BR /&gt;
proc surveyselect data=HMASelect                   &lt;BR /&gt;
		  n=&amp;amp;SampSize&lt;BR /&gt;
                  method=srs                  &lt;BR /&gt;
                  out=&amp;amp;DSNOUT;  &lt;BR /&gt;
run;&lt;BR /&gt;
  &lt;BR /&gt;
&lt;BR /&gt;
ODS PDF FILE="L:\Production\HMASamples\&amp;amp;DSNOUT..PDF";&lt;BR /&gt;
&lt;BR /&gt;
proc print data=&amp;amp;DSNOUT split='*';&lt;BR /&gt;
label Patient_Last_Name = 'Patient*Last*Name'&lt;BR /&gt;
      DischargeDate     = 'Discharge*Date' &lt;BR /&gt;
      Patient_First_Name = 'Patient*First*Name';       &lt;BR /&gt;
var DCYrMonth AdvEncNo DischargeDate Patient_Last_Name Patient_First_Name;&lt;BR /&gt;
format DischargeDate MMDDYY10.;&lt;BR /&gt;
Title "&amp;amp;COMP - &amp;amp;Frequency Random Sample of Inpatient Encounters with an HMA Attending Physician";&lt;BR /&gt;
title2 "&amp;amp;TITLE2";&lt;BR /&gt;
FOOTNOTE "http://ftwweb07/HMFWOutcomes/HMA/SharedDocuments&lt;BR /&gt;
                                      ";&lt;BR /&gt;
run;&lt;BR /&gt;
proc delete data=HMASelect;&lt;BR /&gt;
run; &lt;BR /&gt;
 &lt;BR /&gt;
ODS PDF CLOSE; &lt;BR /&gt;
 &lt;BR /&gt;
%MEND MSELECT;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%MSELECT(Report1,HAR,HAR_MTH_Attending_Sample,25,Monthly,DVT - Lipi</description>
      <pubDate>Wed, 21 Feb 2007 15:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2320#M163</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-02-21T15:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Random Samples</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2321#M164</link>
      <description>Hi, Sheri:&lt;BR /&gt;
  One thing you can do in SAS Macro Language is test and change the value of macro variables, so INSIDE your macro program, you could do this:[pre]&lt;BR /&gt;
&lt;BR /&gt;
data HMASelect (drop=Company);&lt;BR /&gt;
set &amp;amp;DSNIN;&lt;BR /&gt;
if Company="&amp;amp;COMP"; &lt;BR /&gt;
run; &lt;BR /&gt;
&lt;B&gt;&lt;BR /&gt;
*** new code starts;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select nobs into :numobs&lt;BR /&gt;
  from dictionary.tables&lt;BR /&gt;
  where libname="WORK" and&lt;BR /&gt;
        memname="HMASELECT";&lt;BR /&gt;
quit;&lt;BR /&gt;
                   &lt;BR /&gt;
%put before test numobs=&amp;amp;numobs sampsize=&amp;amp;sampsize;&lt;BR /&gt;
           &lt;BR /&gt;
  %if &amp;amp;numobs lt &amp;amp;sampsize %then &lt;BR /&gt;
       %let sampsize = &amp;amp;numobs;&lt;BR /&gt;
      &lt;BR /&gt;
%put after test numobs= &amp;amp;numobs sampsize= &amp;amp;sampsize;&lt;BR /&gt;
*** new code stops;&lt;BR /&gt;
&lt;/B&gt;&lt;BR /&gt;
                        &lt;BR /&gt;
proc surveyselect data=HMASelect &lt;BR /&gt;
n=&amp;amp;SampSize&lt;BR /&gt;
method=srs &lt;BR /&gt;
out=&amp;amp;DSNOUT; &lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
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 &amp;amp;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.)&lt;BR /&gt;
    &lt;BR /&gt;
Then, you can compare &amp;amp;numobs (the internally constructed macro variable) to &amp;amp;sampsize (the macro variable that you pass in) and do the adjustment accordingly.&lt;BR /&gt;
  &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 21 Feb 2007 17:35:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2321#M164</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-02-21T17:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: Random Samples</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2322#M165</link>
      <description>Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
Thank you so much!!  It worked like a charm.  I haven't used Dictionary.tables before.  I will definitely look into it to see what else I can use it for.&lt;BR /&gt;
&lt;BR /&gt;
Are you with SAS?&lt;BR /&gt;
Sheri</description>
      <pubDate>Tue, 27 Feb 2007 19:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2322#M165</guid>
      <dc:creator>Sheri</dc:creator>
      <dc:date>2007-02-27T19:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Random Samples</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2323#M166</link>
      <description>Sheri:&lt;BR /&gt;
  I'm so glad it worked. I absolutely LOVE the SAS Macro Facility -- it is very cool to be able to write self-adjusting programs.&lt;BR /&gt;
  &lt;BR /&gt;
  Yes, I do work for SAS. I teach classes for the Education Division. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; But in a previous job, as a programmer, I wrote lots and lots and lots of macro code. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; really, LOTS....&lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 27 Feb 2007 22:58:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2323#M166</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-02-27T22:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: Random Samples</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2324#M167</link>
      <description>Sheri,&lt;BR /&gt;
&lt;BR /&gt;
You could also try this:&lt;BR /&gt;
&lt;BR /&gt;
******************************;&lt;BR /&gt;
data HMASelect (drop=Company);&lt;BR /&gt;
set &amp;amp;DSNIN;&lt;BR /&gt;
if Company="&amp;amp;COMP"; &lt;BR /&gt;
run;&lt;BR /&gt;
**new code starts;&lt;BR /&gt;
data b;&lt;BR /&gt;
retain obs_n;&lt;BR /&gt;
if _N_=1 then obs_n=total;&lt;BR /&gt;
set HMASelect nobs=total;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
  select case&lt;BR /&gt;
	when obs_n &amp;lt;25 then obs_n&lt;BR /&gt;
		else 25 &lt;BR /&gt;
		end into :ss &lt;BR /&gt;
  from b; 	&lt;BR /&gt;
quit; &lt;BR /&gt;
**new code ends;&lt;BR /&gt;
proc surveyselect data=HMASelect  &lt;BR /&gt;
method=srs out==&amp;amp;DSNOUT &lt;BR /&gt;
n=&amp;amp;ss noprint;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 28 Feb 2007 06:45:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2324#M167</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-02-28T06:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: Random Samples</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2325#M168</link>
      <description>PM,&lt;BR /&gt;
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.  &lt;BR /&gt;
&lt;BR /&gt;
I've never seen a macro variable created in a Proc SQL.&lt;BR /&gt;
Thanks for the insight.&lt;BR /&gt;
Sheri</description>
      <pubDate>Fri, 02 Mar 2007 15:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2325#M168</guid>
      <dc:creator>Sheri</dc:creator>
      <dc:date>2007-03-02T15:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Random Samples</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2326#M169</link>
      <description>You might also try using the SELECTALL option within the PROC SURVEYSELECT statement.</description>
      <pubDate>Wed, 14 Mar 2007 14:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Random-Samples/m-p/2326#M169</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-03-14T14:33:10Z</dc:date>
    </item>
  </channel>
</rss>

