<?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: index unique in more than one var in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/index-unique-in-more-than-one-var/m-p/832929#M329260</link>
    <description>&lt;P&gt;So what you want is that the combination of three variables uniquely identify the observations.&lt;/P&gt;
&lt;P&gt;So in terms of sorting you mean something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=lib1.dataset1 nodupkey ;
   by var1 var2 var3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In terms of indexes that means you want a &lt;A href="https://documentation.sas.com/doc/en/lrcon/9.4/n06cy7dznbx6gen1q9mat8de6rdq.htm#n0bbn5hpjflh72n0z4yu6gdxwsql" target="_self"&gt;composite index&lt;/A&gt;, an index based on the value or two or more variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Sep 2022 16:13:40 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-09-12T16:13:40Z</dc:date>
    <item>
      <title>index unique in more than one var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/index-unique-in-more-than-one-var/m-p/832664#M329134</link>
      <description>&lt;P&gt;Hi everyone, Is it possible to create unique index on more than one variable?&lt;/P&gt;&lt;P&gt;For example I need unique index in three variables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc datasets library=lib1;&lt;BR /&gt;modify dataset1;&lt;BR /&gt;index create var1 / unique;&lt;BR /&gt;index create var2 / unique;&lt;BR /&gt;index create var3 / unique;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;the problem with that code is that it gives me an error since only one can have the only one&lt;/P&gt;&lt;P&gt;ERROR: Duplicate values not allowed on index var1 for file dataset1&lt;/P&gt;&lt;P&gt;and it's okay for var1 to have duplicates but not in combination with var2 and var3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought about concatenating var1, var2, var3 and giving that variable the unique index but I want to see if it is possible to do it directly in those 3 variables.&lt;/P&gt;&lt;P&gt;Because I need that dataset not to have duplicates by combining those 3 variables&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 10 Sep 2022 17:24:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/index-unique-in-more-than-one-var/m-p/832664#M329134</guid>
      <dc:creator>Angel_Saenz</dc:creator>
      <dc:date>2022-09-10T17:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: index unique in more than one var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/index-unique-in-more-than-one-var/m-p/832670#M329136</link>
      <description>&lt;P&gt;You would need to make sure that your index variables have no duplicate values.&lt;/P&gt;
&lt;P&gt;If Var1 =1 appears more than once then you can't use it as a unique index. Period.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you go the concatenation route and any of those variables are numeric you want to make sure to control how you convert numeric to text values (which would be the only way concatenation makes sense) as the default conversion of numeric to text used by the CAT functions may not yield what you expect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Sep 2022 17:59:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/index-unique-in-more-than-one-var/m-p/832670#M329136</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-10T17:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: index unique in more than one var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/index-unique-in-more-than-one-var/m-p/832678#M329139</link>
      <description>thanks ll the variables var var2 and var3 have duplicate, thats is ok, because I need is no is the duplicate value in combination of that three&lt;BR /&gt;So there is no way to establish a unique to 3 variables together unless you do not have duplicates?</description>
      <pubDate>Sat, 10 Sep 2022 19:28:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/index-unique-in-more-than-one-var/m-p/832678#M329139</guid>
      <dc:creator>Angel_Saenz</dc:creator>
      <dc:date>2022-09-10T19:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: index unique in more than one var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/index-unique-in-more-than-one-var/m-p/832714#M329151</link>
      <description>&lt;P&gt;You can create a composite index that's unique as documented &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p03h320ajtd062n1d05vyoqso4yo.htm" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;See sample code below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.demo;
  set sashelp.class;
run;

proc datasets library=work;
  modify demo;
  index create my_index=(sex age height) / unique;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 11 Sep 2022 02:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/index-unique-in-more-than-one-var/m-p/832714#M329151</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-09-11T02:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: index unique in more than one var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/index-unique-in-more-than-one-var/m-p/832928#M329259</link>
      <description>thanks</description>
      <pubDate>Mon, 12 Sep 2022 16:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/index-unique-in-more-than-one-var/m-p/832928#M329259</guid>
      <dc:creator>Angel_Saenz</dc:creator>
      <dc:date>2022-09-12T16:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: index unique in more than one var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/index-unique-in-more-than-one-var/m-p/832929#M329260</link>
      <description>&lt;P&gt;So what you want is that the combination of three variables uniquely identify the observations.&lt;/P&gt;
&lt;P&gt;So in terms of sorting you mean something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=lib1.dataset1 nodupkey ;
   by var1 var2 var3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In terms of indexes that means you want a &lt;A href="https://documentation.sas.com/doc/en/lrcon/9.4/n06cy7dznbx6gen1q9mat8de6rdq.htm#n0bbn5hpjflh72n0z4yu6gdxwsql" target="_self"&gt;composite index&lt;/A&gt;, an index based on the value or two or more variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 16:13:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/index-unique-in-more-than-one-var/m-p/832929#M329260</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-12T16:13:40Z</dc:date>
    </item>
  </channel>
</rss>

