<?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: Create a macro variable with count of diagnosis in SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/418313#M280254</link>
    <description>Thanks for your reply!&lt;BR /&gt;&lt;BR /&gt;The data is not supposed to be dynamic. It is supposed to be historical data. I do not have data to test. I was writing data based on a technical notes.</description>
    <pubDate>Mon, 04 Dec 2017 21:42:34 GMT</pubDate>
    <dc:creator>YGong</dc:creator>
    <dc:date>2017-12-04T21:42:34Z</dc:date>
    <item>
      <title>Create a macro variable with count of diagnosis in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/416416#M280250</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset with patient_ID and patients'&amp;nbsp;diagnosis codes. If a patient had more than one diagnosis, they are in multiple rows. In another words, the dataset is not unique by patient_ID. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to create a counter, which is the maximum number of diagnosis a patient can have.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can somebody tell me, whether the codes below are creating this counter?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;BR /&gt;select left(trim(put(MAX(count),5.))) into: Idy from&lt;BR /&gt;(select count(*) as count&lt;BR /&gt;from&amp;nbsp;data&lt;BR /&gt;group by patient_id);&lt;BR /&gt;QUIT;&lt;BR /&gt;%PUT &amp;amp;Idy;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much.&lt;/P&gt;
&lt;P&gt;Best.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yanyan&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 14:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/416416#M280250</guid>
      <dc:creator>YGong</dc:creator>
      <dc:date>2017-11-27T14:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/416420#M280251</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;Can somebody tell me, whether the codes below are creating this counter? " - why not just run the code and see?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 14:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/416420#M280251</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-27T14:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/416421#M280252</link>
      <description>&lt;P&gt;No. Nobody can tell&amp;nbsp;you, whether the codes below are creating this counter, because we can not see your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Provide some sample of what your data looks like. It makes it much easier to help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 14:55:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/416421#M280252</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-11-27T14:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable with count of diagnosis in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/416436#M280253</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/179742"&gt;@YGong&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset with patient_ID and patients'&amp;nbsp;diagnosis codes. If a patient had more than one diagnosis, they are in multiple rows. In another words, the dataset is not unique by patient_ID. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to create a counter, which is the maximum number of diagnosis a patient can have.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yanyan&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Code reading your data&amp;nbsp; can at best provide the maximum that have occurred. It will never actually provide the number of diagnosis that patient may have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example: The day after you run the data and get X as the maximum count the patient with that count is diagnosed with something.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 15:29:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/416436#M280253</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-27T15:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable with count of diagnosis in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/418313#M280254</link>
      <description>Thanks for your reply!&lt;BR /&gt;&lt;BR /&gt;The data is not supposed to be dynamic. It is supposed to be historical data. I do not have data to test. I was writing data based on a technical notes.</description>
      <pubDate>Mon, 04 Dec 2017 21:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/418313#M280254</guid>
      <dc:creator>YGong</dc:creator>
      <dc:date>2017-12-04T21:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable with count of diagnosis in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/418314#M280255</link>
      <description>If you are a good SAS programmer, you should know what that codes will do. I am writing the codes based on a technical notes, I do not have data to test. Otherwise I would not ask the question.</description>
      <pubDate>Mon, 04 Dec 2017 21:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/418314#M280255</guid>
      <dc:creator>YGong</dc:creator>
      <dc:date>2017-12-04T21:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable with count of diagnosis in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/418393#M280256</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/179742"&gt;@YGong&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;I would change the code to something like&lt;/P&gt;&lt;PRE&gt;proc sql noprint;
  select MAX(count) into: Idy trimmed from
    (select count(distinct diagnosis) as count
    from&amp;nbsp;data
    group by patient_id);
QUIT;
%PUT &amp;amp;Idy;&lt;/PRE&gt;&lt;P&gt;The first change is just simplifying your select expression, and using the TRIMMED keyword to trim leading and trailing blanks from the macro variable. The second is using count(distinct diagnosis) instead of count(*), which will solve two problems:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;If there are records with missing diagnosis, these will not be counted&lt;/LI&gt;&lt;LI&gt;If there are repeat diagnoses for some patients, only unique values will be counted.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Of course, if you are absolutely sure that you only have unique, non-missing diagnoses, your count(*) will work just as well.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 08:37:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/418393#M280256</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-12-05T08:37:51Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable with count of diagnosis in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/418417#M280257</link>
      <description>&lt;P&gt;Great, thank you so much!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the answer I was looking for. Really appreciated your reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards from Paris.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yanyan&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 09:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-count-of-diagnosis-in-SQL/m-p/418417#M280257</guid>
      <dc:creator>YGong</dc:creator>
      <dc:date>2017-12-05T09:13:28Z</dc:date>
    </item>
  </channel>
</rss>

