<?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 index with looping and without macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-index-with-looping-and-without-macro/m-p/861178#M340172</link>
    <description>&lt;P&gt;Typically, my answer to a question that wants to know if something works or not:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try it yourself and see.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think that applies here as well.&lt;/P&gt;</description>
    <pubDate>Mon, 27 Feb 2023 18:27:11 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-02-27T18:27:11Z</dc:date>
    <item>
      <title>Create index with looping and without macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-index-with-looping-and-without-macro/m-p/861165#M340165</link>
      <description>Currently I have the code as below to create the index.&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;Proc sql noprint; &lt;BR /&gt;	   CREATE INDEX division  on sas_prompts_lib_table (division );&lt;BR /&gt;	   CREATE INDEX product_family  on sas_prompts_lib_table (product_family );	   &lt;BR /&gt;	   CREATE INDEX upn  on sas_prompts_lib_table (upn );	 &lt;BR /&gt;quit;&lt;BR /&gt;Now I want to dynamically create the index based on the field name from below SAS macro variable.&lt;BR /&gt;%let current_distinct_var_list = %sysfunc(prxchange(%bquote(s/\*/,/), -1, &amp;amp;amp;current_typ));&lt;BR /&gt;Value of&amp;amp;nbsp;current_distinct_var_list can have any number of fields separated by comma. How to use this macro variable in create index for each field. May be scan function can helps but I'm not sure to implement. I was asked not create any macro for this as this solution will be added to other existing macro.&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;On a related point, I'd like to know&amp;amp;nbsp;if we can create the index on a table (e.g., &amp;amp;nbsp;libname.test) and rename the table (e.g. libname.test_1).&amp;amp;nbsp; Does the index name get updated too?&lt;BR /&gt;&amp;amp;nbsp;</description>
      <pubDate>Mon, 27 Feb 2023 18:58:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-index-with-looping-and-without-macro/m-p/861165#M340165</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-02-27T18:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create index with looping and without macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-index-with-looping-and-without-macro/m-p/861170#M340167</link>
      <description>&lt;P&gt;The primary ways to create looping in SAS are in DATA steps, and via macros. There is no looping in SQL unless you create a macro that works inside of SQL. You can also create indexes in PROC DATASETS, but again, there is no looping without macros that work inside of PROC DATASETS. So ... I think those are your choices.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2023 17:57:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-index-with-looping-and-without-macro/m-p/861170#M340167</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-27T17:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create index with looping and without macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-index-with-looping-and-without-macro/m-p/861176#M340171</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;well, do you answer to the below question as well?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;I'd like to know if we can create the index on a table (e.g.,  libname.test) and rename the table (e.g. libname.test_1).  Does the index name get updated too?&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Feb 2023 18:23:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-index-with-looping-and-without-macro/m-p/861176#M340171</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-02-27T18:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create index with looping and without macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-index-with-looping-and-without-macro/m-p/861178#M340172</link>
      <description>&lt;P&gt;Typically, my answer to a question that wants to know if something works or not:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try it yourself and see.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think that applies here as well.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2023 18:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-index-with-looping-and-without-macro/m-p/861178#M340172</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-27T18:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the index after renaming the dataset name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-index-with-looping-and-without-macro/m-p/861285#M340223</link>
      <description>&lt;P&gt;I've tried the following program to create a index and I want to check whether index will be retained if we rename the dataset name which has index.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I observed that index is not being retained if we rename the&amp;nbsp;dataset name. Is there a way to retain the&amp;nbsp;index even if we rename the&amp;nbsp;dataset name?&lt;/P&gt;
&lt;PRE&gt;data cars;
set sashelp.cars;
run;

proc contents data=cars noprint
out=index_list(keep=libname memname name);
run;

filename code temp;
data _null_;
set index_list;
by libname memname ;
file code;
if first.libname then put 'proc datasets nolist lib=' libname ';' ;
if first.memname then put 'modify ' memname ';' / '  create index ' @;
put name @;
if last.memname then put ';' / 'run;' ;
if last.libname then put 'quit;' ;
run;

%include code/ source2;

data cars_new;
set cars;
run;

proc contents data=cars_new;
run;

proc contents data=cars;
run;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Feb 2023 06:56:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-index-with-looping-and-without-macro/m-p/861285#M340223</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-02-28T06:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the index after renaming the dataset name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-index-with-looping-and-without-macro/m-p/861350#M340253</link>
      <description>&lt;P&gt;First you have to realize that&lt;/P&gt;
&lt;PRE&gt;data cars_new;
set cars;
run;
&lt;/PRE&gt;
&lt;P&gt;Does not "copy" a data set. It builds a completely new data set setting all of its own properties including indexes (none). Second it has to process every single record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to copy to a Different library (COPY means keep the same name in this case so you can't have two sets with the same name in the same library). Or Proc Copy but again it goes to a new library.&lt;/P&gt;
&lt;PRE&gt;libname Dest "&amp;lt;library location&amp;gt;";
Proc datasets library=work;
   copy out=dest; /*name of destination library*/
    select cars;
run;
quit; &lt;/PRE&gt;
&lt;P&gt;Or create the Cars_new and run the index afterwards.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 12:35:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-index-with-looping-and-without-macro/m-p/861350#M340253</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-28T12:35:32Z</dc:date>
    </item>
  </channel>
</rss>

