<?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: check if index exists? in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/check-if-index-exists/m-p/1968#M864</link>
    <description>The ATTRN function offers a "ISINDEX" attributes that solves your problem...&lt;BR /&gt;
&lt;BR /&gt;
DATA _NULL_ ;&lt;BR /&gt;
   dsid = OPEN(yourDataSet) ;&lt;BR /&gt;
   isIndexed = ATTRN(dsid,"ISINDEX") ;&lt;BR /&gt;
   PUT isIndexed = ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
&lt;BR /&gt;
The useful feature of this is that you can use it through the %SYSFUNC macro facility :&lt;BR /&gt;
&lt;BR /&gt;
%SYSFUNC(ATTRN(%SYSFUNC(OPEN(yourDataSet)),ISINDEX))&lt;BR /&gt;
&lt;BR /&gt;
In both cases, you get a 0 or a 1 depending on whether the table has an index (1) or not (0).</description>
    <pubDate>Mon, 18 Dec 2006 18:22:40 GMT</pubDate>
    <dc:creator>Olivier</dc:creator>
    <dc:date>2006-12-18T18:22:40Z</dc:date>
    <item>
      <title>check if index exists?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/check-if-index-exists/m-p/1966#M862</link>
      <description>Is there a way to check if an index already exists on a dataset?</description>
      <pubDate>Fri, 15 Dec 2006 16:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/check-if-index-exists/m-p/1966#M862</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2006-12-15T16:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: check if index exists?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/check-if-index-exists/m-p/1967#M863</link>
      <description>Yeap sure can.... I am going to show you one of many ways to get this information. There are others however it will depend on how you wish to use this.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Data One ( Index = ( x ) ) ;&lt;BR /&gt;
  Do X = 1 To 10 ;&lt;BR /&gt;
    Y = 'A' ;&lt;BR /&gt;
    Output ;&lt;BR /&gt;
  End ;&lt;BR /&gt;
Run ;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Proc SQL ;&lt;BR /&gt;
Select Case When Max( IDXUsage ) Ne '' Then 'Y'&lt;BR /&gt;
            Else                            'N' End  Into: IDXCheck&lt;BR /&gt;
  From Dictionary.Columns&lt;BR /&gt;
    Where MemName = 'ONE' ;&lt;BR /&gt;
Quit ;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%Put &amp;gt;&amp;gt;&amp;amp;IDXCHeck&amp;lt;&amp;lt; ;</description>
      <pubDate>Fri, 15 Dec 2006 21:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/check-if-index-exists/m-p/1967#M863</guid>
      <dc:creator>TobyDunn_hotmail_com</dc:creator>
      <dc:date>2006-12-15T21:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: check if index exists?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/check-if-index-exists/m-p/1968#M864</link>
      <description>The ATTRN function offers a "ISINDEX" attributes that solves your problem...&lt;BR /&gt;
&lt;BR /&gt;
DATA _NULL_ ;&lt;BR /&gt;
   dsid = OPEN(yourDataSet) ;&lt;BR /&gt;
   isIndexed = ATTRN(dsid,"ISINDEX") ;&lt;BR /&gt;
   PUT isIndexed = ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
&lt;BR /&gt;
The useful feature of this is that you can use it through the %SYSFUNC macro facility :&lt;BR /&gt;
&lt;BR /&gt;
%SYSFUNC(ATTRN(%SYSFUNC(OPEN(yourDataSet)),ISINDEX))&lt;BR /&gt;
&lt;BR /&gt;
In both cases, you get a 0 or a 1 depending on whether the table has an index (1) or not (0).</description>
      <pubDate>Mon, 18 Dec 2006 18:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/check-if-index-exists/m-p/1968#M864</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2006-12-18T18:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: check if index exists?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/check-if-index-exists/m-p/1969#M865</link>
      <description>It works! Thanks for your suggestions. I wanted to check if any index already existed on the dataset. If it did not then create one. I modified the code as below:&lt;BR /&gt;
&lt;BR /&gt;
 %macro flg_exist;&lt;BR /&gt;
     %let dsid=%sysfunc(open(dataset_name));&lt;BR /&gt;
     %let ndx_flag=%sysfunc(attrn(&amp;amp;dsid,isindex));&lt;BR /&gt;
     %put Index exists flag= &amp;amp;ndx_flag;&lt;BR /&gt;
&lt;BR /&gt;
     %let rc=%sysfunc(close( &amp;amp;dsid ));&lt;BR /&gt;
     %put Dataset closed return code= &amp;amp;rc;&lt;BR /&gt;
&lt;BR /&gt;
     %if &amp;amp;ndx_flag=1 %then %let ndx_delete=index delete zip5 %str(;);&lt;BR /&gt;
     %else  %if &amp;amp;ndx_flag=0 %then %let ndx_delete=;&lt;BR /&gt;
     %put Index delete statement =&amp;amp;ndx_delete;&lt;BR /&gt;
 %mend;&lt;BR /&gt;
&lt;BR /&gt;
 %flg_exist;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
 proc datasets lib=etldir nolist;&lt;BR /&gt;
    modify dataset_name;&lt;BR /&gt;
    &amp;amp;ndx_delete;&lt;BR /&gt;
    index create zip5;&lt;BR /&gt;
 quit;

&lt;BR /&gt;
Message was edited by: sk at Dec 19, 2006 1:36 PM&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Dec 2006 18:35:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/check-if-index-exists/m-p/1969#M865</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2006-12-19T18:35:30Z</dc:date>
    </item>
  </channel>
</rss>

