<?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: How to create binary variables from multiple observations? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-binary-variables-from-multiple-observations/m-p/790758#M32535</link>
    <description>Thank you very much!</description>
    <pubDate>Tue, 18 Jan 2022 19:43:50 GMT</pubDate>
    <dc:creator>dac_js</dc:creator>
    <dc:date>2022-01-18T19:43:50Z</dc:date>
    <item>
      <title>How to create binary variables from multiple observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-binary-variables-from-multiple-observations/m-p/790733#M32528</link>
      <description>&lt;P&gt;I have the following data:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input&lt;BR /&gt;id var_1 $ var_2 flag_1 flag_2;&lt;BR /&gt;datalines;&lt;BR /&gt;1 ab 1 0 1&lt;BR /&gt;1 ab 1 0 1&lt;BR /&gt;1 ab 1 0 0&lt;BR /&gt;1 ab 1 0 0&lt;BR /&gt;1 ef 7 1 0&lt;BR /&gt;1 ef 7 0 0&lt;BR /&gt;1 ef 7 1 0&lt;BR /&gt;2 ef 3 1 1&lt;BR /&gt;2 xy 4 1 0&lt;BR /&gt;2 xy 4 1 0&lt;BR /&gt;2 xy 4 1 0&lt;BR /&gt;2 xy 5 0 1&lt;BR /&gt;2 xy 5 0 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a table like below:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 240pt;" border="0" width="320" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl63" style="height: 15.0pt; width: 48pt;"&gt;ID&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-left: none; width: 48pt;"&gt;Var_1&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-left: none; width: 48pt;"&gt;Var_2&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-left: none; width: 48pt;"&gt;Flag_1_new&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-left: none; width: 48pt;"&gt;Flag_2_new&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" class="xl63" style="height: 15.0pt; border-top: none;"&gt;1&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;ab&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" class="xl63" style="height: 15.0pt; border-top: none;"&gt;1&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;ef&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;7&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" class="xl63" style="height: 15.0pt; border-top: none;"&gt;2&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;ef&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" class="xl63" style="height: 15.0pt; border-top: none;"&gt;2&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;xy&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" class="xl63" style="height: 15.0pt; border-top: none;"&gt;2&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;xy&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here for each ID, Var_1, and Var_2 combination, I am trying to create one Flag_1_new and one Flag_2_new. The value of this Flag_1_new will be 1 if any of the observation for that group has a flag_1 value of 1 (else 0). Need to repeat the same for Flag_2_new.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope someone can help me to find a solution. Thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 17:58:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-binary-variables-from-multiple-observations/m-p/790733#M32528</guid>
      <dc:creator>dac_js</dc:creator>
      <dc:date>2022-01-18T17:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to create binary variables from multiple observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-binary-variables-from-multiple-observations/m-p/790735#M32529</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/354291"&gt;@dac_js&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Here for each ID, Var_1, and Var_2 combination, I am trying to create one Flag_1_new and one Flag_2_new. The value of this Flag_1_new will be 1 if any of the observation for that group has a flag_1 value of 1 (else 0).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What do you mean by "group"?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 18:00:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-binary-variables-from-multiple-observations/m-p/790735#M32529</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-18T18:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to create binary variables from multiple observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-binary-variables-from-multiple-observations/m-p/790737#M32530</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input
id var_1 $ var_2 flag_1 flag_2;
datalines;
1 ab 1 0 1
1 ab 1 0 1
1 ab 1 0 0
1 ab 1 0 0
1 ef 7 1 0
1 ef 7 0 0
1 ef 7 1 0
2 ef 3 1 1
2 xy 4 1 0
2 xy 4 1 0
2 xy 4 1 0
2 xy 5 0 1
2 xy 5 0 1
;
run;


proc sql;
  create table want as
  select id, var_1, var_2, max(flag_1) as flag_1_new,
         max(flag_2) as flag_2_new
  from have
  group by id, var_1, var_2;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Jan 2022 18:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-binary-variables-from-multiple-observations/m-p/790737#M32530</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2022-01-18T18:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create binary variables from multiple observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-binary-variables-from-multiple-observations/m-p/790757#M32534</link>
      <description>Thank you for your response. I was considering each combination of ID, var_1 and var_2 as group.</description>
      <pubDate>Tue, 18 Jan 2022 19:41:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-binary-variables-from-multiple-observations/m-p/790757#M32534</guid>
      <dc:creator>dac_js</dc:creator>
      <dc:date>2022-01-18T19:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to create binary variables from multiple observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-binary-variables-from-multiple-observations/m-p/790758#M32535</link>
      <description>Thank you very much!</description>
      <pubDate>Tue, 18 Jan 2022 19:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-binary-variables-from-multiple-observations/m-p/790758#M32535</guid>
      <dc:creator>dac_js</dc:creator>
      <dc:date>2022-01-18T19:43:50Z</dc:date>
    </item>
  </channel>
</rss>

