<?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 rename all variable then compute in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575679#M12903</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a database where 12,000 variables are named "A0122_40", "A0122_45", "A0122_50" and so on.&lt;/P&gt;&lt;P&gt;I would like to rename them by keeping in the initial name the numbers from 2 to 5.&lt;/P&gt;&lt;P&gt;I would then like to create variables adding all the columns with the same name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know if better to do two steps (rename then create new variable with SUM) or do directly a procedure to create the new variables.&lt;/P&gt;&lt;P&gt;I already try the rename step from several ways but it still stop because of errors.&lt;/P&gt;&lt;P&gt;Last try was :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc contents data=mine.petitTEST1 out = mine.petitcontents (keep=name where=(name not in ("DEPCOM","NAIS","SEXE"))) noprint; run;&amp;nbsp;data mine.petitTEST2;&lt;BR /&gt;set mine.petitcontents ;&lt;BR /&gt;new_name=cats(name,'=','var',substr(name,2,4));&lt;BR /&gt;output; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select distinct new_name into : renlist separated by ' ' from mine.petitTEST2;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc datasets lib= mine nolist;&lt;BR /&gt;modify petitTEST1 ;&lt;BR /&gt;rename 'A0:' = &amp;amp;renlist. ; run;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Message of error was :&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ERROR 22-322: Expecting un nom. &lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Jul 2019 08:06:53 GMT</pubDate>
    <dc:creator>annaba</dc:creator>
    <dc:date>2019-07-23T08:06:53Z</dc:date>
    <item>
      <title>rename all variable then compute</title>
      <link>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575679#M12903</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a database where 12,000 variables are named "A0122_40", "A0122_45", "A0122_50" and so on.&lt;/P&gt;&lt;P&gt;I would like to rename them by keeping in the initial name the numbers from 2 to 5.&lt;/P&gt;&lt;P&gt;I would then like to create variables adding all the columns with the same name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know if better to do two steps (rename then create new variable with SUM) or do directly a procedure to create the new variables.&lt;/P&gt;&lt;P&gt;I already try the rename step from several ways but it still stop because of errors.&lt;/P&gt;&lt;P&gt;Last try was :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc contents data=mine.petitTEST1 out = mine.petitcontents (keep=name where=(name not in ("DEPCOM","NAIS","SEXE"))) noprint; run;&amp;nbsp;data mine.petitTEST2;&lt;BR /&gt;set mine.petitcontents ;&lt;BR /&gt;new_name=cats(name,'=','var',substr(name,2,4));&lt;BR /&gt;output; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select distinct new_name into : renlist separated by ' ' from mine.petitTEST2;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc datasets lib= mine nolist;&lt;BR /&gt;modify petitTEST1 ;&lt;BR /&gt;rename 'A0:' = &amp;amp;renlist. ; run;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Message of error was :&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ERROR 22-322: Expecting un nom. &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 08:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575679#M12903</guid>
      <dc:creator>annaba</dc:creator>
      <dc:date>2019-07-23T08:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variable then compute</title>
      <link>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575689#M12905</link>
      <description>&lt;P&gt;12,000 variables in a single table? Who comes up with such nonsense?&lt;/P&gt;
&lt;P&gt;My trust in the further survival of humankind just took a big hit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This really cries out for transposing as a first step. Then it's a simple transformation of a single column.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 08:35:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575689#M12905</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-23T08:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variable then compute</title>
      <link>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575697#M12906</link>
      <description>I do with that I can with what administration gave me.&lt;BR /&gt;Could you imagine there is less and help me?&lt;BR /&gt;</description>
      <pubDate>Tue, 23 Jul 2019 08:54:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575697#M12906</guid>
      <dc:creator>annaba</dc:creator>
      <dc:date>2019-07-23T08:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variable then compute</title>
      <link>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575701#M12907</link>
      <description>&lt;P&gt;Do you have a pattern for all those variable names? eg everything starts with "A0"?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 09:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575701#M12907</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-23T09:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variable then compute</title>
      <link>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575702#M12908</link>
      <description>&lt;P&gt;yes they are&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 09:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575702#M12908</guid>
      <dc:creator>annaba</dc:creator>
      <dc:date>2019-07-23T09:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variable then compute</title>
      <link>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575703#M12909</link>
      <description>&lt;P&gt;This is a small sample&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 09:06:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575703#M12909</guid>
      <dc:creator>annaba</dc:creator>
      <dc:date>2019-07-23T09:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variable then compute</title>
      <link>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575704#M12910</link>
      <description>&lt;P&gt;Then do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by .......; /* put all non-"A0" variables here */
run;

proc transpose data=have out=trans;
by .......; /* put all non-"A0" variables here */
var A0:;
run;

data want;
set trans;
_name_ = substr(_name_,2,4);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have lots of missing values, you can remove those observations with a proper where= dataset option during the transpose. You might save a lot of disk space.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 09:07:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575704#M12910</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-23T09:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variable then compute</title>
      <link>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575708#M12911</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;(adapt the libname)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose
  data=sascomm.joel2
  out=trans (
    rename=(col1=value)
    where=(value ne .)
  )
;
by idnew; /* put all non-"A0" variables here */
var A0:;
run;

data sascomm.want;
length name $4;
set trans;
name = substr(_name_,2,4);
drop _name_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Jul 2019 09:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575708#M12911</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-23T09:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variable then compute</title>
      <link>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575712#M12913</link>
      <description>&lt;P&gt;Thank you, that's a big step forward for me.&lt;BR /&gt;How can I keep the occurrence information of each renamed variable (see pictures)?&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NEW.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31217i9992BACA392B7D68/image-size/large?v=v2&amp;amp;px=999" role="button" title="NEW.png" alt="NEW.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="OLD.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31218i1EBC5A436E4C6559/image-size/large?v=v2&amp;amp;px=999" role="button" title="OLD.png" alt="OLD.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 09:26:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575712#M12913</guid>
      <dc:creator>annaba</dc:creator>
      <dc:date>2019-07-23T09:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variable then compute</title>
      <link>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575738#M12918</link>
      <description>&lt;P&gt;It seems to me you need to keep more of _name_, as there are a lot of ambiguities. And the non-missing values of the second picture can't show up in your first picture, as you are a long way away from the years where they will show up.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 11:03:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575738#M12918</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-23T11:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variable then compute</title>
      <link>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575803#M12934</link>
      <description>Thank you so much. Great help.</description>
      <pubDate>Tue, 23 Jul 2019 13:44:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/rename-all-variable-then-compute/m-p/575803#M12934</guid>
      <dc:creator>annaba</dc:creator>
      <dc:date>2019-07-23T13:44:29Z</dc:date>
    </item>
  </channel>
</rss>

