<?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 Change all variable names into an indexed sequence in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244612#M6429</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a very wide dataset with 229 variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to change thoese variables' names into an enumerated sequence such that my final result will look like so:&lt;/P&gt;
&lt;P&gt;sq_1 sq_2 sq_3.... sq_227.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried this macro but it failed:&lt;/P&gt;
&lt;P&gt;%macro rename(lib,dsn,newname);&lt;BR /&gt;proc contents data=&amp;amp;lib..&amp;amp;dsn;&lt;BR /&gt;title 'before renaming';&lt;BR /&gt;run;&lt;BR /&gt;proc sql noprint; &lt;BR /&gt;%rename(WORK,call_qs1);&lt;BR /&gt; from dictionary.tables&lt;BR /&gt; where libname="&amp;amp;LIB" and memname="&amp;amp;DSN";&lt;BR /&gt; select distinct(name) into :var1-:var%trim(%left(&amp;amp;num_vars))&lt;BR /&gt; from dictionary.columns&lt;BR /&gt; where libname="&amp;amp;LIB" and memname="&amp;amp;DSN";&lt;BR /&gt; quit;&lt;BR /&gt;run;&lt;BR /&gt;proc datasets library = &amp;amp;LIB;&lt;BR /&gt;modify &amp;amp;DSN;&lt;BR /&gt;rename&lt;BR /&gt;%do i = 1 %to &amp;amp;num_vars.;&lt;BR /&gt;&amp;amp;&amp;amp;var&amp;amp;i = &amp;amp;sq._&amp;amp;i.&lt;BR /&gt;%end;&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;run;&lt;BR /&gt;proc contents data=&amp;amp;lib..&amp;amp;dsn.;&lt;BR /&gt;title 'after renaming';&lt;BR /&gt;run;&lt;BR /&gt;%mend rename;&lt;/P&gt;
&lt;P&gt;%rename(WORK,call_qs1,call_qs2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As always, Thank you for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jan 2016 07:48:20 GMT</pubDate>
    <dc:creator>BchBnz</dc:creator>
    <dc:date>2016-01-20T07:48:20Z</dc:date>
    <item>
      <title>Change all variable names into an indexed sequence</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244612#M6429</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a very wide dataset with 229 variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to change thoese variables' names into an enumerated sequence such that my final result will look like so:&lt;/P&gt;
&lt;P&gt;sq_1 sq_2 sq_3.... sq_227.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried this macro but it failed:&lt;/P&gt;
&lt;P&gt;%macro rename(lib,dsn,newname);&lt;BR /&gt;proc contents data=&amp;amp;lib..&amp;amp;dsn;&lt;BR /&gt;title 'before renaming';&lt;BR /&gt;run;&lt;BR /&gt;proc sql noprint; &lt;BR /&gt;%rename(WORK,call_qs1);&lt;BR /&gt; from dictionary.tables&lt;BR /&gt; where libname="&amp;amp;LIB" and memname="&amp;amp;DSN";&lt;BR /&gt; select distinct(name) into :var1-:var%trim(%left(&amp;amp;num_vars))&lt;BR /&gt; from dictionary.columns&lt;BR /&gt; where libname="&amp;amp;LIB" and memname="&amp;amp;DSN";&lt;BR /&gt; quit;&lt;BR /&gt;run;&lt;BR /&gt;proc datasets library = &amp;amp;LIB;&lt;BR /&gt;modify &amp;amp;DSN;&lt;BR /&gt;rename&lt;BR /&gt;%do i = 1 %to &amp;amp;num_vars.;&lt;BR /&gt;&amp;amp;&amp;amp;var&amp;amp;i = &amp;amp;sq._&amp;amp;i.&lt;BR /&gt;%end;&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;run;&lt;BR /&gt;proc contents data=&amp;amp;lib..&amp;amp;dsn.;&lt;BR /&gt;title 'after renaming';&lt;BR /&gt;run;&lt;BR /&gt;%mend rename;&lt;/P&gt;
&lt;P&gt;%rename(WORK,call_qs1,call_qs2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As always, Thank you for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 07:48:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244612#M6429</guid>
      <dc:creator>BchBnz</dc:creator>
      <dc:date>2016-01-20T07:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: Change all variable names into an indexed sequence</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244617#M6430</link>
      <description>&lt;P&gt;What was your problem, and what does your log look like?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 08:14:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244617#M6430</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-01-20T08:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: Change all variable names into an indexed sequence</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244619#M6432</link>
      <description>&lt;P&gt;Sas just crashes after I run the macro.&lt;/P&gt;
&lt;P&gt;I am unable to see the log, unfortunately.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 08:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244619#M6432</guid>
      <dc:creator>BchBnz</dc:creator>
      <dc:date>2016-01-20T08:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Change all variable names into an indexed sequence</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244623#M6434</link>
      <description>&lt;P&gt;Did you notice that you have a recursion in your macro?&lt;/P&gt;
&lt;P&gt;It calls itself right after the proc sql noprint;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 08:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244623#M6434</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-01-20T08:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Change all variable names into an indexed sequence</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244626#M6435</link>
      <description>Oh yes, I can see that there is a log output repeating itself. I couldn't not quite read what it says as it goes fast and SAS crashes.</description>
      <pubDate>Wed, 20 Jan 2016 08:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244626#M6435</guid>
      <dc:creator>BchBnz</dc:creator>
      <dc:date>2016-01-20T08:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: Change all variable names into an indexed sequence</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244629#M6436</link>
      <description>&lt;P&gt;Here is an example :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
run;





proc transpose data=have(obs=0) out=temp;
 var _all_;
run;
data temp;
 set temp;
 length name $ 20;
 name=cats('sq_',_n_);
run;
proc sql;
 select cats(_name_,'=',name) into : rename separated by  ' '
  from temp;
quit;
proc datasets library=work nodetails nolist;
 modify have;
 rename &amp;amp;rename ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jan 2016 09:08:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244629#M6436</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-01-20T09:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: Change all variable names into an indexed sequence</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244639#M6437</link>
      <description>&lt;P&gt;Well, you can do it with arrays:&lt;/P&gt;
&lt;PRE&gt;data have;
  vara=1; varxyz=2; abc=4;
run;

data want (keep=sq_:);
  set have;
  array aq_{*} vara--abc;
  array sq_{3} 8.;
  do i=1 to 3;
    sq_{i}=aq_{i};
  end;
run;&lt;/PRE&gt;
&lt;P&gt;What I don't understand however is why this does not work, I assume the array is defined as _temporary_ but can't seem to find an option to make it permanent:&lt;/P&gt;
&lt;PRE&gt;data have;
  vara=1; varxyz=2; abc=4;
run;

data want (keep=sq_:);
  set have;
  array sq_{*} vara--abc;
run;&lt;/PRE&gt;
&lt;P&gt;To my mind the above should work?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 10:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244639#M6437</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-20T10:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: Change all variable names into an indexed sequence</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244641#M6438</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9﻿&lt;/a&gt;: Isn't this just the usual behavior of arrays in SAS ("temporarily identifying a group of variables" [online help])? That is, in your example you can &lt;EM&gt;refer to &lt;/EM&gt;the existing variables&amp;nbsp;&lt;FONT face="courier new,courier"&gt;vara&lt;/FONT&gt;, ..., &lt;FONT face="courier new,courier"&gt;abc&lt;/FONT&gt; &lt;EM&gt;as&lt;/EM&gt; &lt;FONT face="courier new,courier"&gt;sq_&lt;STRONG&gt;[&lt;/STRONG&gt;1&lt;STRONG&gt;]&lt;/STRONG&gt;&lt;/FONT&gt;, ..., &lt;FONT face="courier new,courier"&gt;sq_&lt;STRONG&gt;[&lt;/STRONG&gt;3&lt;STRONG&gt;]&lt;/STRONG&gt;&lt;/FONT&gt; within the data step where the array is defined, but this does not change the variables' names and does not create new variables &lt;FONT face="courier new,courier"&gt;sq_1&lt;/FONT&gt;, ..., &lt;FONT face="courier new,courier"&gt;sq_3&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 10:55:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244641#M6438</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-20T10:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: Change all variable names into an indexed sequence</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244642#M6439</link>
      <description>&lt;P&gt;Well, this is what is confusing me. &amp;nbsp;In the first example, I have the temporary reference to the variables, and I have another array, and basically copy to the sq_ array. &amp;nbsp;This works, and we get the variables sq_1-sq_3 - note I have not put any other options on that. &amp;nbsp;In the second instance, aq_1-aq_3 is created as I can reference it in the code, but it is removed before the end of the datastep as its considered temporary. &amp;nbsp;So the question is whys does:&lt;/P&gt;
&lt;P&gt;array sq_{3} 8.;&lt;/P&gt;
&lt;P&gt;Create the variables sq_1-sq3 and keep them, but:&lt;/P&gt;
&lt;P&gt;array aq_{*} vara--abc;&lt;/P&gt;
&lt;P&gt;Creates aq_1-aq_3, but creates a temporary so get dropped.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And is there an options I can pubt on that line:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;array aq_{*} _nottemporary_ vara--abc;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;To avoid this, as with that optin the OP's request is simply a one line statement then.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 11:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244642#M6439</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-20T11:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Change all variable names into an indexed sequence</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244651#M6443</link>
      <description>&lt;P&gt;Thank you very much this suggestion worked just fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you ever so much. A quick explanation for the following line would be great if you would:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 &lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;_name_&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'='&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;name&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;into&lt;/SPAN&gt; : &lt;SPAN class="token function"&gt;rename&lt;/SPAN&gt; separated &lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt;  &lt;SPAN class="token string"&gt;' '&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; temp&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Is it storing all variables names in a vector called rename?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 12:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244651#M6443</guid>
      <dc:creator>BchBnz</dc:creator>
      <dc:date>2016-01-20T12:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Change all variable names into an indexed sequence</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244658#M6445</link>
      <description>&lt;P&gt;"Is it storing all variables names in a vector called rename?"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, but in SAS speak this is not a vector, it's a macro variable.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 13:11:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244658#M6445</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-01-20T13:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: Change all variable names into an indexed sequence</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244661#M6446</link>
      <description>Oh okay. I got it!&lt;BR /&gt;&lt;BR /&gt;Thank you ever so much.</description>
      <pubDate>Wed, 20 Jan 2016 13:14:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244661#M6446</guid>
      <dc:creator>BchBnz</dc:creator>
      <dc:date>2016-01-20T13:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: Change all variable names into an indexed sequence</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244666#M6447</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9﻿&lt;/a&gt;:&amp;nbsp;As I see it, an array is a list of variables which can (individually) be referenced by the array name followed by a subscript in brackets (or parentheses or curly brackets ...) after the array has been defined, but only within the same data step (and not in DROP/KEEP/RENAME statements or the corresponding dataset options). In a &lt;FONT face="courier new,courier"&gt;_TEMPORARY_&lt;/FONT&gt; array, these variables (!) exist only during the data step where the array is defined (and can only be referenced using the subscript notation, are automatically retained, but not written to the output dataset).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In an array definition like &lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;array sq_{3} 8;&lt;FONT face="arial,helvetica,sans-serif"&gt;&amp;nbsp;(no need for a period after the 8 -- it's the length, not a format) the list of variables is &lt;EM&gt;implicitly&lt;/EM&gt; defined by default as sq_1, sq_2, sq_3. In a definition like&amp;nbsp;&lt;FONT face="courier new,courier"&gt;array aq_{*} vara varxyz abc;&lt;/FONT&gt; the list of variables is &lt;EM&gt;explicitly&lt;/EM&gt; defined. Special variable lists such as &lt;FONT face="courier new,courier"&gt;vara--abc&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;c:&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;_numeric_&lt;/FONT&gt;&amp;nbsp;require the existence of corresponding variables in the PDV. In these cases&amp;nbsp;the order of ARRAY and, e.g., SET statement is important.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;In all cases where the list of variables does &lt;EM&gt;not require&lt;/EM&gt;&amp;nbsp;the existence of the variables in the PDV, one of the following two cases applies to each variable in the list:&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;FONT face="arial, helvetica, sans-serif"&gt;&lt;SPAN style="line-height: normal;"&gt;the variable exists in the PDV: then it can henceforth (but only within the same data step, and see further restrictions above) be referenced&amp;nbsp;as the respective array element, i.e. with the subscript notation like aq_{2}&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face="arial, helvetica, sans-serif"&gt;&lt;SPAN style="line-height: normal;"&gt;&lt;SPAN&gt;the variable does not exist in the PDV: then it is created as a new variable (&lt;EM&gt;and&lt;/EM&gt; can be referenced ... as above)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;FONT face="arial, helvetica, sans-serif"&gt;&lt;SPAN style="line-height: normal;"&gt;&lt;SPAN&gt;So, in your first example,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;array aq_{*} vara--abc;&lt;/FONT&gt; just enables you to refer, e.g., to the existing variable abc as aq_{3} (but &lt;EM&gt;not&lt;/EM&gt; as aq_3, there is no such variable in the PDV!),&amp;nbsp;this is case 1. Since dataset HAVE does not contain variables sq_1, sq_2, sq_3, the array definition&amp;nbsp;&lt;FONT face="courier new,courier"&gt;array sq_{3} 8;&lt;/FONT&gt; creates new variables (i.e. adds them to the PDV) with those default names, this is case 2. The new variables are by default kept in the output dataset, like any other new variables.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial, helvetica, sans-serif"&gt;&lt;SPAN style="line-height: normal;"&gt;&lt;SPAN&gt;I think, the above explains already why the second example (with&amp;nbsp;&lt;FONT face="courier new,courier"&gt;keep=sq_:&lt;/FONT&gt;) does not work: There is no variable whose name starts with sq_ in the PDV and the KEEP= option would not even accept a reference like sq_{1} (with the intention to keep variable vara).&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There seems to be no option to kind of duplicate a list of existing variables, so that&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;array aq_{*} &lt;EM&gt;option&lt;/EM&gt; vara--abc; &lt;FONT face="arial,helvetica,sans-serif"&gt;would create new variables aq_1, ... with the same values as vara, ... Instead, it's &lt;EM&gt;either&lt;/EM&gt; case 1 &lt;EM&gt;or&lt;/EM&gt; case 2 that applies to each individual variable in the list. In the definition&amp;nbsp;&lt;FONT face="courier new,courier"&gt;array aq_{*} &lt;SPAN&gt;vara newvar abc; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;case 1 would apply to vara and abc and case 2 to newvar (i.e., a&amp;nbsp;new variable newvar would be created). If dataset HAVE happened to contain variables sq_1 and sq_3, but not sq_2, the statement &lt;FONT face="courier new,courier"&gt;array sq_{3};&lt;/FONT&gt; would create only one new variable, sq_2.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial, helvetica, sans-serif"&gt;&lt;SPAN style="line-height: normal;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 13:29:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Change-all-variable-names-into-an-indexed-sequence/m-p/244666#M6447</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-20T13:29:26Z</dc:date>
    </item>
  </channel>
</rss>

