<?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 retain indexes after using set statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/800012#M314640</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292735"&gt;@Swapnil_21&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Given the column names are you implementing within one of the Risk Stratum solutions? If so then I've created lately a macro that does what you're after. Happy to share if you provide a bit more detail.&lt;/P&gt;</description>
    <pubDate>Fri, 04 Mar 2022 00:08:30 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2022-03-04T00:08:30Z</dc:date>
    <item>
      <title>How to retain indexes after using set statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799233#M314242</link>
      <description>&lt;P&gt;I have input dataset which has one index, I need to create replica of input and need to maintain the indexes also. But when i use set command, indexes are getting lost.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my input dataset have in inbound library&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="767"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="115"&gt;ACCOUNT_ID&lt;/TD&gt;
&lt;TD width="191"&gt;DATA_DATE&lt;/TD&gt;
&lt;TD width="68"&gt;TCE&lt;/TD&gt;
&lt;TD width="105"&gt;TOT_LMT&lt;/TD&gt;
&lt;TD width="111"&gt;SOURCE_SYSTEM_CODE&lt;/TD&gt;
&lt;TD width="177"&gt;BASEL_RETAIL_CORP_CODE&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;RAM3000007&lt;/TD&gt;
&lt;TD&gt;31-Jan-22&lt;/TD&gt;
&lt;TD&gt;1000&lt;/TD&gt;
&lt;TD&gt;3400&lt;/TD&gt;
&lt;TD&gt;RAM&lt;/TD&gt;
&lt;TD&gt;CONS&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;RAM3000015&lt;/TD&gt;
&lt;TD&gt;31-Jan-22&lt;/TD&gt;
&lt;TD&gt;12000&lt;/TD&gt;
&lt;TD&gt;4600&lt;/TD&gt;
&lt;TD&gt;RAM&lt;/TD&gt;
&lt;TD&gt;CONS&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is the describe statement&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;BR /&gt;create table INBOUND.CE_RAM_PIT( compress=BINARY bufsize=131072 )&lt;BR /&gt;(&lt;BR /&gt;ACCOUNT_ID char(30) format=$30. label='Account Identifier',&lt;BR /&gt;DATA_DATE num format=DATE9. label='Data Date',&lt;BR /&gt;TCE num format=17.2 label='Total Committed Exposure',&lt;BR /&gt;TOT_LMT num format=17.2 label='Total Limit',&lt;BR /&gt;SOURCE_SYSTEM_CODE char(3) format=$3. label='Source System Code',&lt;BR /&gt;BASEL_RETAIL_CORP_CODE char(10) format=$10. label='Basel Retail Corporate Code'&lt;BR /&gt;&lt;BR /&gt;);&lt;BR /&gt;create index ECL_MODEL_GROUP_CODE on INBOUND.CE_RAM_PIT(ACCOUNT_ID);&lt;BR /&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now , I need to create new dataset in other directory and retain indexes, when use set indexes are lost.&lt;/P&gt;
&lt;P&gt;I have tried Proc datasets , in that case indexes are retained, however, I need to do certain dataset operations using datastep like below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data outbound.CE_RAM_PIT;&lt;/P&gt;
&lt;P&gt;set inbound.CE_RAM_PIT;&lt;/P&gt;
&lt;P&gt;new_field1=TCE*70;&lt;/P&gt;
&lt;P&gt;new_field2=TCE/20;&lt;/P&gt;
&lt;P&gt;new_field3=put(new_field2,8.);&lt;/P&gt;
&lt;P&gt;new_field4=TOT_LMT/ 3400;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;when i run above code, my indexes are lost. Any help on either retaining index or rebuilding indexes using same proc sql would help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 01:57:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799233#M314242</guid>
      <dc:creator>Swapnil_21</dc:creator>
      <dc:date>2022-03-01T01:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain indexes after using set statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799236#M314244</link>
      <description>&lt;P&gt;You are making a new dataset.&amp;nbsp; If you want SAS to make the index then tell it so using the INDEX= dataset option.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/ledsoptsref/n1aaucjme18e43n1jfgz8zsijv88.htm#n1te9tceklywtbn1p0ely8hndc4x" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/ledsoptsref/n1aaucjme18e43n1jfgz8zsijv88.htm#n1te9tceklywtbn1p0ely8hndc4x&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outbound.CE_RAM_PIT (compress=binary index=(account_no));
  set inbound.CE_RAM_PIT;
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that there is no need to complicate your code by using SQL syntax to create the datasets or the indexes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data INBOUND.CE_RAM_PIT(compress=BINARY index=(account_id));
  attrib ACCOUNT_ID length=$30 label='Account Identifier';
  attrib DATA_DATE format=DATE9. label='Data Date';
  attrib TCE       format=17.2 label='Total Committed Exposure';
  attrib TOT_LMT   format=17.2 label='Total Limit';
  attrib SOURCE_SYSTEM_CODE length=$3 label='Source System Code';
  attrib BASEL_RETAIL_CORP_CODE length=$3 label='Basel Retail Corporate Code';
  stop;
  call missing(of _all_);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also there is no need to attach display formats to character strings, SAS already knows how to display character strings.&lt;/P&gt;
&lt;P&gt;If your total variables will actually use the 16 significant digits the display formats attached to them imply then you might have issues.&amp;nbsp; SAS floating point numbers can only store about 15 decimal digits precisely.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 02:45:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799236#M314244</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-01T02:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain indexes after using set statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799239#M314246</link>
      <description>Problem is , there are about 16 datasets and I dont know what index is present on which dataset</description>
      <pubDate>Tue, 01 Mar 2022 03:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799239#M314246</guid>
      <dc:creator>Swapnil_21</dc:creator>
      <dc:date>2022-03-01T03:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain indexes after using set statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799241#M314248</link>
      <description>&lt;P&gt;Why do you care?&lt;/P&gt;
&lt;P&gt;I almost never use indexes with SAS datasets.&lt;/P&gt;
&lt;P&gt;When I do it is part of some large complex project that has dedicated code for creating the datasets.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 03:21:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799241#M314248</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-01T03:21:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain indexes after using set statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799259#M314262</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292735"&gt;@Swapnil_21&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Problem is , there are about 16 datasets and I dont know what index is present on which dataset&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You could use proc contents or have a look at sashelp.vtable to find the datasets not having an index.&lt;/P&gt;
&lt;P&gt;An index is only retained if you are using proc append or proc copy all other procs and the data step won't create an index automatically.&lt;/P&gt;
&lt;P&gt;But i concur with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;: maintaining indexes is hardly worth the effort.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 07:58:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799259#M314262</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-03-01T07:58:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain indexes after using set statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799268#M314270</link>
      <description>&lt;P&gt;PROC APPEND with non existent BASE data set should do the trrick.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 09:59:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799268#M314270</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2022-03-01T09:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain indexes after using set statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799309#M314293</link>
      <description>&lt;P&gt;That works great for copy the data (or using OBS=0 dataset option just the structure), but does not support adding the new variables.&amp;nbsp; You might combine it with the ability of PROC SQL to alter a dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class (index=(sex));
  set sashelp.class;
run;
proc delete data=new; run;

proc append data=class(obs=0) base=new force;
run;

proc sql;
  alter table new add bmi num label='Body Mass Index';
quit; 

data new ;
  if 0 then modify new;
  set class;
  bmi = (703*weight)/(height*height) ;
  output;
run;

proc contents data=new;
run;

proc print;
  by sex;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But just because it is possible does not mean I would recommend doing that.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead:&lt;/P&gt;
&lt;P&gt;1) don't bother with indexes unless you really need from.&lt;/P&gt;
&lt;P&gt;2) If you have to constantly create new datasets in a particular structure then define a macro (or even just a macro variable) that you can use to generate the code to build the new dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 13:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799309#M314293</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-01T13:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain indexes after using set statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799969#M314607</link>
      <description>&lt;P&gt;This macro can be used for getting the constraints:&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&lt;A href="https://core.sasjs.io/mp__getconstraints_8sas.html" target="_blank"&gt;https://core.sasjs.io/mp__getconstraints_8sas.html&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;And this one can be used for setting them again:&amp;nbsp;&amp;nbsp;&lt;A href="https://core.sasjs.io/mp__createconstraints_8sas.html" target="_blank"&gt;https://core.sasjs.io/mp__createconstraints_8sas.html&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 21:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/799969#M314607</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2022-03-03T21:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain indexes after using set statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/800012#M314640</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292735"&gt;@Swapnil_21&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Given the column names are you implementing within one of the Risk Stratum solutions? If so then I've created lately a macro that does what you're after. Happy to share if you provide a bit more detail.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 00:08:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-indexes-after-using-set-statement/m-p/800012#M314640</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-03-04T00:08:30Z</dc:date>
    </item>
  </channel>
</rss>

