<?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 binary variable from duplicate values in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-duplicate-values/m-p/389285#M3286</link>
    <description>&lt;P&gt;Similar method, slightly different calculation, since that's exactly what FIRST does, flip the indicator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
  by X1;

 y=1-first.x1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 19 Aug 2017 00:57:46 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-08-19T00:57:46Z</dc:date>
    <item>
      <title>Create a binary variable from duplicate values</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-duplicate-values/m-p/389282#M3283</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;X1 &amp;nbsp; &amp;nbsp;&amp;nbsp;X&lt;SPAN&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;X3 &amp;nbsp; &amp;nbsp;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; ... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; ... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;and I want to create a new variable (called Y) with binary values, which makes the data as such:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;X1 &amp;nbsp; &amp;nbsp;&amp;nbsp;X&lt;SPAN&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;X3 &amp;nbsp; &amp;nbsp;... &amp;nbsp;Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; ... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; ... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In other words, it puts 0 for a unique value of X1, 0 for the first non-unique value, and 1 for the remainder of non-unique values. I was wondering how it can be done in SAS. Any idea/help is really appreciated!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Aug 2017 00:43:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-duplicate-values/m-p/389282#M3283</guid>
      <dc:creator>Alireza_Boloori</dc:creator>
      <dc:date>2017-08-19T00:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create a binary variable from duplicate values</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-duplicate-values/m-p/389283#M3284</link>
      <description>&lt;P&gt;Assuming data is sorted by X1 then do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
  by X1;
       if first.x1  then y=0; else y=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Aug 2017 00:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-duplicate-values/m-p/389283#M3284</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-08-19T00:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create a binary variable from duplicate values</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-duplicate-values/m-p/389284#M3285</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt; Thank you for the answer!</description>
      <pubDate>Sat, 19 Aug 2017 00:55:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-duplicate-values/m-p/389284#M3285</guid>
      <dc:creator>Alireza_Boloori</dc:creator>
      <dc:date>2017-08-19T00:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create a binary variable from duplicate values</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-duplicate-values/m-p/389285#M3286</link>
      <description>&lt;P&gt;Similar method, slightly different calculation, since that's exactly what FIRST does, flip the indicator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
  by X1;

 y=1-first.x1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Aug 2017 00:57:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-duplicate-values/m-p/389285#M3286</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-19T00:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create a binary variable from duplicate values</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-duplicate-values/m-p/389286#M3287</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; Thanks!</description>
      <pubDate>Sat, 19 Aug 2017 00:59:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-duplicate-values/m-p/389286#M3287</guid>
      <dc:creator>Alireza_Boloori</dc:creator>
      <dc:date>2017-08-19T00:59:20Z</dc:date>
    </item>
  </channel>
</rss>

