<?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 keep an index in a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-an-index-in-a-dataset/m-p/52123#M10979</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I have a macro that receives a dataset by parameter. This dataset may contain and index, built like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA TEST (index=(IDXPR = (USER_ID USER_TYPE REGISTRATION_DATE) /UNIQUE /NOMISS));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The macro code uses a DATA TEST; SET TEST; step to update the table. Therefore, it erases the index.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to keep the index with the same structure as it had before the SET TEST; ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried to search about rebuild, but from what I found, it looked like the command is used just to repair indexes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also tried the PROC CONTENTS, but I did not find the UNIQUE and NOMISS options there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Feb 2012 15:24:32 GMT</pubDate>
    <dc:creator>Rah</dc:creator>
    <dc:date>2012-02-11T15:24:32Z</dc:date>
    <item>
      <title>How to keep an index in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-an-index-in-a-dataset/m-p/52123#M10979</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I have a macro that receives a dataset by parameter. This dataset may contain and index, built like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA TEST (index=(IDXPR = (USER_ID USER_TYPE REGISTRATION_DATE) /UNIQUE /NOMISS));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The macro code uses a DATA TEST; SET TEST; step to update the table. Therefore, it erases the index.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to keep the index with the same structure as it had before the SET TEST; ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried to search about rebuild, but from what I found, it looked like the command is used just to repair indexes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also tried the PROC CONTENTS, but I did not find the UNIQUE and NOMISS options there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Feb 2012 15:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-an-index-in-a-dataset/m-p/52123#M10979</guid>
      <dc:creator>Rah</dc:creator>
      <dc:date>2012-02-11T15:24:32Z</dc:date>
    </item>
    <item>
      <title>How to keep an index in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-an-index-in-a-dataset/m-p/52124#M10980</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am reminded of the old joke:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: sans-serif; line-height: 19px; text-align: -webkit-auto; background-color: #ffffff;"&gt;PATIENT: Doctor, it hurts when I do &lt;/SPAN&gt;&lt;EM style="color: #000000; font-family: sans-serif; line-height: 19px; text-align: -webkit-auto; background-color: #ffffff;"&gt;this&lt;/EM&gt;&lt;SPAN style="color: #000000; font-family: sans-serif; line-height: 19px; text-align: -webkit-auto; background-color: #ffffff;"&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: sans-serif; line-height: 19px; text-align: -webkit-auto; background-color: #ffffff;"&gt;DOCTOR: Don't &lt;/SPAN&gt;&lt;EM style="color: #000000; font-family: sans-serif; line-height: 19px; text-align: -webkit-auto; background-color: #ffffff;"&gt;do&lt;/EM&gt;&lt;SPAN style="color: #000000; font-family: sans-serif; line-height: 19px; text-align: -webkit-auto; background-color: #ffffff;"&gt; that.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: sans-serif; line-height: 19px; text-align: -webkit-auto; background-color: #ffffff;"&gt;Seriously look into using the UPDATE statement of PROC SQL.&amp;nbsp; Or if you are just adding observations you could use PROC APPEND.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: sans-serif; line-height: 19px; text-align: -webkit-auto; background-color: #ffffff;"&gt;Otherwise force the macro's user to provide you with the necessary dataset options to have the dataset re-created with the options that they want.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macor myupdate(in=,out=);&lt;/P&gt;&lt;P&gt;data &amp;amp;out;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set &amp;amp;in;&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%myupdate(in=test,out=&lt;SPAN style="background-color: #eef4f9;"&gt;TEST (index=(IDXPR = (USER_ID USER_TYPE REGISTRATION_DATE) /UNIQUE /NOMISS)));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #eef4f9;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Feb 2012 17:06:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-an-index-in-a-dataset/m-p/52124#M10980</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-02-11T17:06:46Z</dc:date>
    </item>
    <item>
      <title>How to keep an index in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-an-index-in-a-dataset/m-p/52125#M10981</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A DATA step with a MODIFY statement would also preserve the index.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rah should understand that the DATA TEST; SET TEST; construct does not change an existing table. Rather it creates a new table which replaces the pre-existing one.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Feb 2012 03:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-an-index-in-a-dataset/m-p/52125#M10981</guid>
      <dc:creator>Howles</dc:creator>
      <dc:date>2012-02-12T03:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep an index in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-an-index-in-a-dataset/m-p/52126#M10982</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you MUST rewrite the data set to update it, this concept macro might help:&lt;/P&gt;&lt;PRE&gt; 
%macro Update(master,update,by);
/*This macro will update data in the master data set, preserving indexes*/
%let master=%qupcase(&amp;amp;master);
%let update=%qupcase(&amp;amp;update);
%let memname=%qscan(&amp;amp;master,2,.);

%if &amp;amp;memname= %then %do;
&amp;nbsp;&amp;nbsp; %let libname=WORK;
&amp;nbsp;&amp;nbsp; %let memname=&amp;amp;master;
%end;
%else %do;
&amp;nbsp;&amp;nbsp; %let libname=%qscan(&amp;amp;master,1,.);
%end;

proc sort data=sashelp.VINDEX (where=(libname="&amp;amp;libname" and MEMNAME="&amp;amp;memname"))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out=indexes;
&amp;nbsp;&amp;nbsp; by INDXNAME INDXPOS;
run;

data _null_;
&amp;nbsp;&amp;nbsp; length Indx Names $2000;
&amp;nbsp;&amp;nbsp; retain indx names;
&amp;nbsp;&amp;nbsp; set indexes nobs=nobs end=last;
&amp;nbsp;&amp;nbsp; by INDXNAME;
&amp;nbsp;&amp;nbsp; if nobs=0 then do;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symputx ('index',' ');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop;
&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp; IF _n_=1 then do;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; indx="(INDEX=(";
&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp; if first.INDXNAME then do;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Names='';
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; indx=catx(' ',indx,indxname,'=(');
&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp; Names=catx(' ',Names,Name);
&amp;nbsp;&amp;nbsp; if last.INDXNAME then do;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; indx=catx(' ',indx,names,')');
&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp; if last then do;
&amp;nbsp;&amp;nbsp; call symputx ('index',CATX(' ',indx,'))'));
&amp;nbsp;&amp;nbsp; end;
run;

data &amp;amp;master &amp;amp;Index;
&amp;nbsp;&amp;nbsp; update &amp;amp;master &amp;amp;update;
&amp;nbsp;&amp;nbsp; by &amp;amp;by;
run;
%mend;

/*Make a dataset with an index - we will update this one*/
Data TEST (index=(Name=(Name) Comp=(Age Height)));
&amp;nbsp; set sashelp.class;
run;

/*Make a dataset with the update values*/
data UpDates;
&amp;nbsp; set sashelp.class (obs=2 keep= Name Age Height);
&amp;nbsp; Age=21;
&amp;nbsp; Height=70;
run;

/*Use the update macro to update the dataset and preserve the indexes*/
options mprint;
%Update(work.test,work.updates, Name)
 &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Feb 2012 04:08:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-an-index-in-a-dataset/m-p/52126#M10982</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2012-02-12T04:08:01Z</dc:date>
    </item>
    <item>
      <title>How to keep an index in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-an-index-in-a-dataset/m-p/52127#M10983</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Worked perfectly! I just added two more lines into your concept macro, and would like to share it: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the part:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if last.INDXNAME then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; indx=catx(' ',indx,names,')');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've added:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if last.INDXNAME then do;&lt;/P&gt;&lt;P&gt; indx=catx(' ',indx,names,')');&lt;/P&gt;&lt;P&gt; if unique = 'yes' then indx=catx(' ',indx,'/UNIQUE');&lt;/P&gt;&lt;P&gt; if nomiss = 'yes' then indx=catx(' ',indx,'/NOMISS');&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So it's also possible to keep the unique and nomiss.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for the help and the patience in writing the code!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Apr 2012 12:29:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-an-index-in-a-dataset/m-p/52127#M10983</guid>
      <dc:creator>Rah</dc:creator>
      <dc:date>2012-04-04T12:29:45Z</dc:date>
    </item>
  </channel>
</rss>

