<?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: Randomly select one record per patient, per month? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785028#M250505</link>
    <description>Your code shows a variable called quarter and your data provided initially has months? Does that matter?</description>
    <pubDate>Wed, 08 Dec 2021 21:55:22 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-12-08T21:55:22Z</dc:date>
    <item>
      <title>Randomly select one record per patient, per month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785023#M250501</link>
      <description>&lt;P&gt;Hello, I have longitudinal data with multiple health records for multiple dates, per patient. I created a numerical variable for month to simplify (values: 1-12) and because it's for a time series.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For now I am trying to &lt;STRONG&gt;randomly&lt;/STRONG&gt; select one patient record, per month. so it's ok to have multiple records for a person, as long as there's only one chosen per month. I've been trying to figure out proc surveyselect but cannot get it per patient/per month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id&amp;nbsp; pt_id&amp;nbsp; &amp;nbsp;month&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;1&amp;nbsp; XXY&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; XXY&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;3&amp;nbsp; XXY&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;4&amp;nbsp; ZZH&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;5&amp;nbsp; ZZH&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;6&amp;nbsp; KKJ&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;7&amp;nbsp; KKJ&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;8&amp;nbsp; KKJ&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;9&amp;nbsp; KKJ&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;10 KKJ&amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;&lt;P&gt;11 KKJ&amp;nbsp; &amp;nbsp; &amp;nbsp;6&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2021 21:28:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785023#M250501</guid>
      <dc:creator>Student77</dc:creator>
      <dc:date>2021-12-08T21:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly select one record per patient, per month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785024#M250502</link>
      <description>&lt;P&gt;Please show the code you've tried in PROC SURVEYSELECT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/332727"&gt;@Student77&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello, I have longitudinal data with multiple health records for multiple dates, per patient. I created a numerical variable for month to simplify (values: 1-12) and because it's for a time series.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For now I am trying to &lt;STRONG&gt;randomly&lt;/STRONG&gt; select one patient record, per month. so it's ok to have multiple records for a person, as long as there's only one chosen per month. I've been trying to figure out proc surveyselect but cannot get it per patient/per month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id&amp;nbsp; pt_id&amp;nbsp; &amp;nbsp;month&amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; XXY&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; XXY&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; XXY&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;4&amp;nbsp; ZZH&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;5&amp;nbsp; ZZH&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;6&amp;nbsp; KKJ&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;7&amp;nbsp; KKJ&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;
&lt;P&gt;8&amp;nbsp; KKJ&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;9&amp;nbsp; KKJ&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;10 KKJ&amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;
&lt;P&gt;11 KKJ&amp;nbsp; &amp;nbsp; &amp;nbsp;6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2021 21:33:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785024#M250502</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-08T21:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly select one record per patient, per month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785025#M250503</link>
      <description>*randomly select one record per quarter to represent pt;&lt;BR /&gt;proc surveyselect data=udt.aim2b outall out=aim2_random_b sampsize=1;&lt;BR /&gt;strata patid quarter;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;but the samplesize I'm unsure of--either way, every time I try to run it'll freeze after a while and shut off</description>
      <pubDate>Wed, 08 Dec 2021 21:38:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785025#M250503</guid>
      <dc:creator>Student77</dc:creator>
      <dc:date>2021-12-08T21:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly select one record per patient, per month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785028#M250505</link>
      <description>Your code shows a variable called quarter and your data provided initially has months? Does that matter?</description>
      <pubDate>Wed, 08 Dec 2021 21:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785028#M250505</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-08T21:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly select one record per patient, per month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785030#M250507</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id  pt_id $  month;
cards;
1  XXY      1
2  XXY      2
3  XXY      1
4  ZZH      2
5  ZZH      2
6  KKJ      3
7  KKJ      4
8  KKJ      3
9  KKJ      5
10 KKJ     5
11 KKJ     6
;;;;

proc sort data=have;
by month;
run;

proc surveyselect data=have method=srs sampsize=1 out=want;
strata month;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to remove the patid from the STRATA statement. Otherwise you're saying pick one per patient per month.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2021 22:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785030#M250507</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-08T22:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly select one record per patient, per month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785063#M250528</link>
      <description>When I used this code, it gave me back just one observation - I think that's what sampsize=1 means.&lt;BR /&gt;&lt;BR /&gt;I'm trying to get data showing for ex:&lt;BR /&gt;1 XXY 1&lt;BR /&gt;2 XXY 2&lt;BR /&gt;4 ZZH 2&lt;BR /&gt;6 KKJ 3&lt;BR /&gt;7 KKJ 4&lt;BR /&gt;9 KKJ 5&lt;BR /&gt;11 KKJ 6&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;So a single patient can be included multiple times but once PER month.&lt;BR /&gt;and I'm trying to randomly select the one per month, per patient&lt;BR /&gt;</description>
      <pubDate>Thu, 09 Dec 2021 04:01:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785063#M250528</guid>
      <dc:creator>Student77</dc:creator>
      <dc:date>2021-12-09T04:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly select one record per patient, per month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785067#M250530</link>
      <description>&lt;P&gt;How large is your input dataset?&amp;nbsp; How many patient*month (or patient*quarter) combinations are there?&lt;/P&gt;
&lt;P&gt;What type of variable is QUARTER (or month)?&amp;nbsp; If it is actually a date value that is using a format to display only the quarter or year-quarter using an attached format then you might have many more combinations that you thought.&lt;/P&gt;
&lt;P&gt;Also how many of you patient*month combinations only have one observation already?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would first try turning off the listing output of PROC SURVERYSELECT by adding the NOPRINT option.&amp;nbsp; Perhaps your session is just locking up because you are generating pages and pages of output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a lot of patient*month combinations with only one observation already the SAS LOG might get really large with the notes that PROC SURVEYSELECT generates when that happens.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are doing a SRS then perhaps just do it yourself instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
create view for_selection as 
  select *, random('uniform') as rand 
  from udt.aim2b&amp;nbsp;
&amp;nbsp;&amp;nbsp;order&amp;nbsp;by&amp;nbsp;patid, quarter,&amp;nbsp;rand
;
quit;
data&amp;nbsp;aim2_random_b&amp;nbsp;;
&amp;nbsp;&amp;nbsp;set&amp;nbsp;for_selction; &amp;nbsp;&amp;nbsp;
  by&amp;nbsp;patid&amp;nbsp;quarter&amp;nbsp;;
&amp;nbsp;&amp;nbsp;if&amp;nbsp;first.quarter;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 04:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785067#M250530</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-09T04:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly select one record per patient, per month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785068#M250531</link>
      <description>It's about 60,000 records and I would say that about 50% already only have 1 per patient per month. (sorry ignore "quarter")&lt;BR /&gt;I had already tried noprint, because yes it kept printing endless log info. I created an indicator for month instead of dealing with date formats.&lt;BR /&gt;&lt;BR /&gt;I tried this code and I got:&lt;BR /&gt;"&lt;BR /&gt;ERROR: Function RANDOM could not be located.&lt;BR /&gt;ERROR: SQL View WORK.FOR_SELECTION could not be processed.&lt;BR /&gt;"&lt;BR /&gt;Is this an issue with my SAS?&lt;BR /&gt;&lt;BR /&gt;Thanks for your help&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 09 Dec 2021 04:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785068#M250531</guid>
      <dc:creator>Student77</dc:creator>
      <dc:date>2021-12-09T04:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly select one record per patient, per month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785069#M250532</link>
      <description>This worked! just needed to change "random()" to rand()</description>
      <pubDate>Thu, 09 Dec 2021 04:54:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785069#M250532</guid>
      <dc:creator>Student77</dc:creator>
      <dc:date>2021-12-09T04:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly select one record per patient, per month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785070#M250533</link>
      <description>&lt;P&gt;Just an issue with my memory.&lt;/P&gt;
&lt;P&gt;RAND()&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0fpeei0opypg8n1b06qe4r040lv.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0fpeei0opypg8n1b06qe4r040lv.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 04:55:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-select-one-record-per-patient-per-month/m-p/785070#M250533</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-09T04:55:00Z</dc:date>
    </item>
  </channel>
</rss>

