<?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 how to create a dummy variable based on the number of appearance of a certain value ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409690#M100104</link>
    <description>&lt;P&gt;Hello!&lt;BR /&gt;I wanna ask how to create a dummy variable based on the number of appearance of a certain value ?&lt;BR /&gt;For example, I have dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID . diagnosis hospital&lt;BR /&gt;2022 .&amp;nbsp; &amp;nbsp;1 .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&lt;BR /&gt;2022 .&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&lt;BR /&gt;2023 .&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&lt;BR /&gt;2023 .&amp;nbsp; &amp;nbsp;1 .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;D&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Say a certain disease Y is classified positive if it's been diagnosed positive at lease twice. In this class, ID 2023 would be identified having the disease Y. I want to assign another variable called Y as dummy variable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 if count (diagnosis = 1) &amp;gt;= 2 by each ID&lt;/P&gt;&lt;P&gt;0 otherwise&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to do it with proc sql? Thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Nov 2017 02:06:48 GMT</pubDate>
    <dc:creator>Viveme789</dc:creator>
    <dc:date>2017-11-02T02:06:48Z</dc:date>
    <item>
      <title>how to create a dummy variable based on the number of appearance of a certain value ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409690#M100104</link>
      <description>&lt;P&gt;Hello!&lt;BR /&gt;I wanna ask how to create a dummy variable based on the number of appearance of a certain value ?&lt;BR /&gt;For example, I have dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID . diagnosis hospital&lt;BR /&gt;2022 .&amp;nbsp; &amp;nbsp;1 .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&lt;BR /&gt;2022 .&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&lt;BR /&gt;2023 .&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&lt;BR /&gt;2023 .&amp;nbsp; &amp;nbsp;1 .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;D&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Say a certain disease Y is classified positive if it's been diagnosed positive at lease twice. In this class, ID 2023 would be identified having the disease Y. I want to assign another variable called Y as dummy variable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 if count (diagnosis = 1) &amp;gt;= 2 by each ID&lt;/P&gt;&lt;P&gt;0 otherwise&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to do it with proc sql? Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 02:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409690#M100104</guid>
      <dc:creator>Viveme789</dc:creator>
      <dc:date>2017-11-02T02:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a dummy variable based on the number of appearance of a certain value ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409693#M100107</link>
      <description>&lt;P&gt;I don't know about SQL, but it is easy with MEANS and a DATA step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x(drop=miss);
input ID miss diagnosis hospital $;
datalines;
2022 .   1           A
2022 .   0           B
2023 .   1           A
2023 .   1          D
;
proc means; class id; var diagnosis; output out=b sum=sum; run;
proc print; run;

data all(drop=_: sum);
   merge x b(where=(sum &amp;gt;= 2 and n(id)) in=f); by id;
   y = f;
   run;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Nov 2017 02:30:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409693#M100107</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-11-02T02:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a dummy variable based on the number of appearance of a certain value ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409695#M100108</link>
      <description>Thanks for the effort! But I still have to do it with proc sql required by the professor.</description>
      <pubDate>Thu, 02 Nov 2017 02:39:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409695#M100108</guid>
      <dc:creator>Viveme789</dc:creator>
      <dc:date>2017-11-02T02:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a dummy variable based on the number of appearance of a certain value ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409699#M100112</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Select *, Sum(diagnosis) as num_diag, case when calculated num_diag&amp;gt;1 then 1 else 0 end as indicator&lt;/P&gt;
&lt;P&gt;from have&lt;/P&gt;
&lt;P&gt;group by ID;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This may or may not be the approach your instructor was expecting. I would highly suggest reviewing your lecture notes and seeing if a specific example wasn’t provided.&amp;nbsp;&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/175222"&gt;@Viveme789&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello!&lt;BR /&gt;I wanna ask how to create a dummy variable based on the number of appearance of a certain value ?&lt;BR /&gt;For example, I have dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID . diagnosis hospital&lt;BR /&gt;2022 .&amp;nbsp; &amp;nbsp;1 .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&lt;BR /&gt;2022 .&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&lt;BR /&gt;2023 .&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&lt;BR /&gt;2023 .&amp;nbsp; &amp;nbsp;1 .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;D&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say a certain disease Y is classified positive if it's been diagnosed positive at lease twice. In this class, ID 2023 would be identified having the disease Y. I want to assign another variable called Y as dummy variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 if count (diagnosis = 1) &amp;gt;= 2 by each ID&lt;/P&gt;
&lt;P&gt;0 otherwise&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to do it with proc sql? Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 03:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409699#M100112</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-02T03:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a dummy variable based on the number of appearance of a certain value ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409703#M100115</link>
      <description>Thank you! I have a question regarding the statement:&lt;BR /&gt;Sum(diagnosis) as num_diag&lt;BR /&gt;is it summing the number of diagnosis for each patient, which is actually the number of rows per patient, or summing (diagnosis = 1)?&lt;BR /&gt;And there's no specific example in the lecture notes:/&lt;BR /&gt;Thank you.</description>
      <pubDate>Thu, 02 Nov 2017 03:31:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409703#M100115</guid>
      <dc:creator>Viveme789</dc:creator>
      <dc:date>2017-11-02T03:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a dummy variable based on the number of appearance of a certain value ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409705#M100117</link>
      <description>It is an addition of the diagnosis value for each patient not the number of rows for each patient. The latter is done by count(variable).</description>
      <pubDate>Thu, 02 Nov 2017 03:40:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409705#M100117</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2017-11-02T03:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a dummy variable based on the number of appearance of a certain value ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409813#M100146</link>
      <description>&lt;PRE&gt;
data x(drop=miss);
input ID miss diagnosis hospital $;
datalines;
2022 .   1           A
2022 .   0           B
2023 .   1           A
2023 .   1          D
;

proc sql;
select *,sum(diagnosis=1)&amp;gt;=2 as flag 
 from x
  group by id;
quit;


&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Nov 2017 13:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409813#M100146</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-11-02T13:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a dummy variable based on the number of appearance of a certain value ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409842#M100162</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175222"&gt;@Viveme789&lt;/a&gt; wrote:&lt;BR /&gt;Thank you! I have a question regarding the statement:&lt;BR /&gt;Sum(diagnosis) as num_diag&lt;BR /&gt;is it summing the number of diagnosis for each patient, which is actually the number of rows per patient, or summing (diagnosis = 1)?&lt;BR /&gt;And there's no specific example in the lecture notes:/&lt;BR /&gt;Thank you.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the values are 0/1 its the same thing.....&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 14:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-dummy-variable-based-on-the-number-of-appearance/m-p/409842#M100162</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-02T14:37:00Z</dc:date>
    </item>
  </channel>
</rss>

