<?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: Rename all variables at once in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-at-once/m-p/533943#M146446</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
set sashelp.class;
rename name=var1 sex = var2 age = var3 height = var4 weight = var5;
run;



proc transpose data=class(obs=0) out=temp;
var _all_;
run;
data temp;
 set temp;
 n=input(compress(_name_,,'kd'),best.);
 new_name=cats(compress(_name_,,'d'),put(n,z4.));
run;

data _null_;
 set temp end=last;
 if _n_=1 then call execute('proc datasets library=work nolist nodetails;modify class ; rename ');
 call execute(cats(_name_,'=',new_name));
if last then call execute(';quit;');
run;


proc print data=class;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 08 Feb 2019 14:48:24 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-02-08T14:48:24Z</dc:date>
    <item>
      <title>Rename all variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-at-once/m-p/533814#M146410</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;I am trying to import data from a csv file and the only row I want to import is the first row. Following code is working, but I am getting my variable name as Var1, Var2, Var3 etc. Is there a way to name my variables as Var0001, Var0002, Var0003 during the import. I will appreciate any help on this.&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;OPTIONS obs=1;
PROC IMPORT DATAFILE="C:\Test.csv" 
OUT=Want
     DBMS=csv REPLACE;
	 GETNAMES=NO;
	 DATAROW=1;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Feb 2019 03:34:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-at-once/m-p/533814#M146410</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2019-02-08T03:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-at-once/m-p/533816#M146411</link>
      <description>&lt;P&gt;You can rename it in one step, but not sure you can do that in PROC IMPORT.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
set sashelp.class;
rename name=var1 sex = var2 age = var3 height = var4 weight = var5;
run;

data want;
set class;
rename var1-var5 = var001-var005;
run;

proc contents data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE class="table" aria-label="Variables"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="c b header" colspan="4" scope="colgroup"&gt;Alphabetic List of Variables and Attributes&lt;/TH&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;#&lt;/TH&gt;
&lt;TH class="b header" scope="col"&gt;Variable&lt;/TH&gt;
&lt;TH class="b header" scope="col"&gt;Type&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Len&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="data"&gt;var001&lt;/TD&gt;
&lt;TD class="data"&gt;Char&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="data"&gt;var002&lt;/TD&gt;
&lt;TD class="data"&gt;Char&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="data"&gt;var003&lt;/TD&gt;
&lt;TD class="data"&gt;Num&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="data"&gt;var004&lt;/TD&gt;
&lt;TD class="data"&gt;Num&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="data"&gt;var005&lt;/TD&gt;
&lt;TD class="data"&gt;Num&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that I'm assuming you're using SAS Base and have moved the question to the programming forum. If you're using Data Flux or Data Integration Studio there may be different options and I can move this question back to the Data Management forum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35631"&gt;@mlogan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;I am trying to import data from a csv file and the only row I want to import is the first row. Following code is working, but I am getting my variable name as Var1, Var2, Var3 etc. Is there a way to name my variables as Var0001, Var0002, Var0003 during the import. I will appreciate any help on this.&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;OPTIONS obs=1;
PROC IMPORT DATAFILE="C:\Test.csv" 
OUT=Want
     DBMS=csv REPLACE;
	 GETNAMES=NO;
	 DATAROW=1;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 03:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-at-once/m-p/533816#M146411</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-08T03:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-at-once/m-p/533824#M146413</link>
      <description>&lt;P&gt;If your source dataset had more random variable names that did not lend themselves to using variable list syntax, then here is a more generic approach:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* simulate import of data ;
data have;
   set sashelp.cars (obs=3);
run;

* create metadata ;
proc contents data=have out=contents noprint;
run;
proc sql noprint;
   select name into :vars separated by " " from contents order by varnum;
   drop table contents;
quit;

* macro to rename columns ;
%macro code;
&amp;amp;word=Var%sysfunc(putn(&amp;amp;__iter__,z3.))
%mend;

* use proc datasets to rename ;
proc datasets lib=work nolist;
   modify have;
   rename %loop(&amp;amp;vars);
   run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/loop.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/loop.sas&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 04:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-at-once/m-p/533824#M146413</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-02-08T04:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-at-once/m-p/533875#M146425</link>
      <description>&lt;P&gt;Why not drop the guessing procedure fully.&amp;nbsp; Write a datastep to import your CSV, using the structure that you know best (presumably using the data import agreement you have).&amp;nbsp; This way you don't let the system guess what your data is supposed to look like, can have your given data structure, and it be repeatable and QC'able.&amp;nbsp; Proc import is only useful for getting the base code to work with, run it once, then copy the code generated from the log and modify it to match the data that only you know best.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 09:43:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-at-once/m-p/533875#M146425</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-08T09:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-at-once/m-p/533943#M146446</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
set sashelp.class;
rename name=var1 sex = var2 age = var3 height = var4 weight = var5;
run;



proc transpose data=class(obs=0) out=temp;
var _all_;
run;
data temp;
 set temp;
 n=input(compress(_name_,,'kd'),best.);
 new_name=cats(compress(_name_,,'d'),put(n,z4.));
run;

data _null_;
 set temp end=last;
 if _n_=1 then call execute('proc datasets library=work nolist nodetails;modify class ; rename ');
 call execute(cats(_name_,'=',new_name));
if last then call execute(';quit;');
run;


proc print data=class;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Feb 2019 14:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-at-once/m-p/533943#M146446</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-02-08T14:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-at-once/m-p/533985#M146454</link>
      <description>Hi ScottBass,&lt;BR /&gt;Your code is giving me an error. Would you please find the error. I am getting the following error. Thanks.&lt;BR /&gt;&lt;BR /&gt;164  PROC DATASETS LIB=work NOLIST;&lt;BR /&gt;165     MODIFY have;&lt;BR /&gt;WARNING: Apparent invocation of macro LOOP not resolved.&lt;BR /&gt;166     RENAME %loop(&amp;amp;vars);&lt;BR /&gt;               -&lt;BR /&gt;               22&lt;BR /&gt;               76&lt;BR /&gt;NOTE: Enter RUN; to continue or QUIT; to end the procedure.&lt;BR /&gt;ERROR 22-322: Expecting a name.&lt;BR /&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;BR /&gt;167     RUN;&lt;BR /&gt;&lt;BR /&gt;NOTE: Statements not processed because of errors noted above.&lt;BR /&gt;168  QUIT;&lt;BR /&gt;</description>
      <pubDate>Fri, 08 Feb 2019 16:04:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-at-once/m-p/533985#M146454</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2019-02-08T16:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-at-once/m-p/534371#M146629</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35631"&gt;@mlogan&lt;/a&gt;&amp;nbsp;Click the github link, save the macro, and either compile it or save it in your sasautos path.&amp;nbsp; You may also need to download other github macros such as %parmv.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 05:26:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-at-once/m-p/534371#M146629</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-02-11T05:26:27Z</dc:date>
    </item>
  </channel>
</rss>

