<?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: Dynamically change the name of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663795#M198229</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/197542"&gt;@A_Swoosh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;SASfiles is my way to call all my datasets; it looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Filename
Data1
Data2
Data3
Data4
...
Data16&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2. Yea, I don't think I'm following that aspect of it.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To call the macro for a specific table in work would look like:&lt;/P&gt;
&lt;PRE&gt;%renameVars(work.mytable,varname_stdz);&lt;/PRE&gt;
&lt;P&gt;If you've got a SAS table with the table names (your table "sasfiles") then here how you can call the macro once per observation.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set sasfiles;
  rc=dosubl( cats('%renameVars(',filename,',varname_stdz);') );
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;N.B: Make sure that the value of your variable &lt;EM&gt;Filename&lt;/EM&gt; contains &amp;lt;libref&amp;gt;.&amp;lt;table name&amp;gt;. If you omit the libref then the macro will look in WORK.&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jun 2020 01:16:15 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2020-06-24T01:16:15Z</dc:date>
    <item>
      <title>Dynamically change the name of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663671#M198167</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've looked through these forums and examples to potentially dynamically change the name of my variables in my datasets but to no avail.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem: I want to change the names of my variables in each of the 16 datasets that I'm feeding into SAS. Each dataset may or may not have all the same variables (i.e., some datasets may have more variables than others). I'm looking for a way to dynamically change variable names through each iteration of my SAS datasets only looking at the variables in those datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Solution (?):&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Proc sql to create variable list, then use an array and do loop to iterate through each dataset?&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Read an excel file into sas and use rename?&lt;/LI&gt;&lt;LI&gt;use a %let and rename&lt;/LI&gt;&lt;LI&gt;a macro&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Have:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset 1&lt;/P&gt;&lt;PRE&gt;ProvID NPI Txnmy_cd1 Txnmy_cd2 Txnmy_cd3 Spec_cd1 Spec_cd2&lt;/PRE&gt;&lt;P&gt;Dataset 2&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ProvID NPI txnmy_cd txnmy_cd2 Spec_cd Spec_cd1&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and so on...&lt;/P&gt;&lt;P&gt;Want:&lt;/P&gt;&lt;P&gt;Dataset 1&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ProvID NPI Taxonomy Taxonomy2 Taxonomy3 ProvSpec1 ProvSpec2 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Dataset 2&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ProvID NPI Taxonomy Taxonomy2 Taxonomy3 ProvSpec1 ProvSpec2 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Any suggestions would be helpful...Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 03:33:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663671#M198167</guid>
      <dc:creator>A_Swoosh</dc:creator>
      <dc:date>2020-06-20T03:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the name of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663672#M198168</link>
      <description>&lt;P&gt;From your example I understand that you want to change prefixes of variable names.&lt;/P&gt;
&lt;P&gt;You cam use sql dictionary.columns or sashelp.vcolumn to get variable names of a dataset,&lt;/P&gt;
&lt;P&gt;create the rename statement as a macro variable to be used with proc datasets and rename&amp;nbsp;&lt;/P&gt;
&lt;P&gt;variables without copying the dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next code is tesed:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
     ProvID=1;
     Txnmy_cd1=21;
     Txnmy_cd2=22;
     Txnmy_cd3=23;
     Spec_cd1 =31;
     Spec_cd2 =32;
run;

%let lib = WORK;
%let dsn = HAVE;
data _null_;
 set sashelp.vcolumn end=eof;
     where libname = "&amp;amp;lib" and memname = "&amp;amp;dsn";
	 length new_name $32 rename $1000;
	 retain rename;
	 if substr(name,1,6) = 'Txnmy_' 
	    then new_name = 'TAXONOMY' || substr(name,7); else
	 if substr(name,1,7) = 'Spec_cd'
	    then new_name = 'PROVSPEC' || substr(name,8); 
	 else new_name = ' ';
     if not missing(new_name) then		
	 rename = compbl(rename) || ' ' || strip(name) || '=' || strip(new_name);
	 if eof then call symput('RENAME', strip(rename));
run;
%put &amp;amp;rename;   /* to be checked in the log */

proc datasets lib=&amp;amp;lib;
      modify &amp;amp;dsn;
	  rename &amp;amp;rename;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 05:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663672#M198168</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-06-20T05:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the name of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663680#M198171</link>
      <description>&lt;P&gt;Here some code which should give you a lot of flexibility. Just expand informat $varname_stdz to whatever renaming you need and add the tables in scope to the data _null_ step at the end.&lt;/P&gt;
&lt;P&gt;You could also pass in different informat names should you need it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
  array vars {*} ProvID NPI Txnmy_cd1 Txnmy_cd2;
  stop;
run;

data have2;
  array vars {*} ProvID NPI txnmy_cd;
  stop;
run;


%macro renameVars(tbl,infmt_stdz);
  %local lib;
  %let lib=%upcase(%scan(WORK.&amp;amp;tbl,-2,.));
  %let tbl=%upcase(%scan(&amp;amp;tbl,-1,.));

  %local rename_vars;
  %let rename_vars=;
  proc sql noprint;
    select cats(name,'=',input(name,$&amp;amp;infmt_stdz.32.)) 
      into :rename_vars separated by ' '
    from dictionary.columns
    where 
      libname="&amp;amp;lib" 
      and memname="&amp;amp;tbl"
      and not missing(input(name,$&amp;amp;infmt_stdz.32.))
    ;
  quit;
  
  %if %nrbquote(&amp;amp;rename_vars) ne %nrbquote() %then
    %do;
      proc datasets lib=&amp;amp;lib nolist;
        modify &amp;amp;tbl;
          rename &amp;amp;rename_vars;
        run;
      quit;
    %end;
%mend;

proc format;
  invalue $varname_stdz(default=32 upcase)
    'TXNMY_CD'  = 'Taxonomy'
    'TXNMY_CD1' = 'Taxonomy'
    'TXNMY_CD2' = 'Taxonomy2'
    other=' '
    ;
run;

data _null_;
  infile datalines dsd dlm=' ' truncover;
  input tbls :$41. infmt_stdz :$32.;
  infmt_stdz=coalescec(infmt_stdz,'varname_stdz');
  rc=dosubl(cats('%renameVars(',tbls,',',infmt_stdz,');'));
  datalines;
have1
work.have2
haveNot
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

NOTE: Renaming variable Txnmy_cd1 to Taxonomy.
NOTE: Renaming variable Txnmy_cd2 to Taxonomy2.
NOTE: MODIFY was successful for WORK.HAVE1.DATA.
NOTE: PROCEDURE DATASETS used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

NOTE: Renaming variable txnmy_cd to Taxonomy.
NOTE: MODIFY was successful for WORK.HAVE2.DATA.
NOTE: PROCEDURE DATASETS used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

NOTE: No rows were selected.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 01:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663680#M198171</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-24T01:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the name of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663768#M198212</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the response. I'm a little lost with your code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the top, you have:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
  array vars {*} ProvID NPI Txnmy_cd1 Txnmy_cd2;
  stop;
run;

data have2;
  array vars {*} ProvID NPI txnmy_cd;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If I'm automating through each dataset, what does this accomplish?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second, I'm not sure I follow this end piece here specifically the have1 work.have2 havenot;:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile datalines dsd dlm=' ' truncover;
  input tbls :$41. infmt_stdz :$32.;
  infmt_stdz=coalescec(infmt_stdz,'varname_stdz');
  rc=dosubl(cats('%renameVars(',tbls,',',infmt_stdz,');'));
  datalines;
have1
work.have2
haveNot
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have written a piece of code to iterate through each of my datasets. I used this to call out specific things that I want to use throughout.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	        data _NULL_  ;
	                set sasfiles;
	                if _n_ = &amp;amp;i.;
	                call symputx('name',SAS_name);
					call symputx('plan',substr(SAS_name,5,3));
	        run;
				%put "&amp;amp;name.";
				%put "&amp;amp;plan.";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I then formatted my code slightly to modify a few elements here:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;			data &amp;amp;name. (drop=start_date end_date);
				set outdta.&amp;amp;name.;

				/* Create plan name */
				Plan="&amp;amp;plan.";
/*				Plan_LName=put(plan, $Plan_Abbrev.);*/

/*				/* Format date variables */*/;
				StartDate=input(start_date, yymmdd10.);
				EndDate=input(end_date, yymmdd10.);

				format StartDate EndDate mmddyy10. plan $4.;
			run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I then want to use your formatting suggestion to rename my variables using a longer list than the one you did (for example) which I added to my infmt_stdz format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My end result is that I want to automate this as much as possible and let the data drive my code so from one year to the next, I can simply change the format you mentioned and let it ride...&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 23:49:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663768#M198212</guid>
      <dc:creator>A_Swoosh</dc:creator>
      <dc:date>2020-06-20T23:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the name of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663769#M198213</link>
      <description>&lt;P&gt;Hi Shmeul,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the response. Yes, I want to essentially create prefixes and suffix for a newly standardized list of variables. To follow up, I did have a question for you code; is there a way to automate this process without creating these conditional statements and substrings? The list I provided was a small subset of the variables that I want to either prefix/suffix so I would then essentially have to generate conditional statements for each variable prefix/suffix I use unless there is some way to further automate this process? So for example, I have city, state, address,zip information but want to change those with a prefix of "Prov" too.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 23:53:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663769#M198213</guid>
      <dc:creator>A_Swoosh</dc:creator>
      <dc:date>2020-06-20T23:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the name of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663774#M198215</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Top&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;That's just creating sample tables &lt;EM&gt;have1&lt;/EM&gt; and &lt;EM&gt;have2&lt;/EM&gt; so I've got something to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Second&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;That code is calling the macro via dosubl() once per table. The macro then renames the variables; and the macro is written in a way that if you pass in a not existing table name -&amp;nbsp;&lt;EM&gt;haveNot&lt;/EM&gt; in the sample code - then just nothing will happen but the macro doesn't fail.&lt;/P&gt;
&lt;P&gt;You can replace this data step with whatever suits you. You just need the dosubl() bit:&lt;/P&gt;
&lt;PRE&gt;rc=dosubl(cats('%renameVars(',tbls,',',infmt_stdz,');'));&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;tbls&lt;/STRONG&gt;: You can replace this with the variable that has the name of the table you where you want to rename variables. If the values of the variable only have the table name then the macro will look for a table in WORK; else pass in a name with the libref like mylib.mytable&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;infmt_stdz&lt;/STRONG&gt;: This variable has the name of the Informat you want to use (name without a dot). You could also just hard-code that when calling the macro, i.e. if your informat has a name like $varname_stdz then below would work.&lt;/P&gt;
&lt;PRE&gt;rc=dosubl(cats('%renameVars(',tbls,',varname_stdz);'));&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jun 2020 00:16:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663774#M198215</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-21T00:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the name of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663777#M198216</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Listed Separately */
proc format; 
  invalue $varname_stdz(default=32 upcase)
  	'Prov_type' = 'ProvType'
	'Prov_typeB' = 'ProvType'
    'TXNMY_CD'  = 'Taxonomy'
    'TXNMY_CD1' = 'Taxonomy'
    'SPEC_CD' = 'ProvSpec1'
    'SPEC_CD1' = 'ProvSpec1'
    other = ' '
;
run;

%macro loopy;
	proc sql noprint;
		select max(monotonic()) into :completion from sasfiles;
		%let completion=&amp;amp;completion;
	quit;
	%put &amp;amp;completion.;

	        %let i = 1;
	        %do %while( &amp;amp;i.&amp;lt;= &amp;amp;completion.);

	        data _NULL_  ;
	                set sasfiles;
	                if _n_ = &amp;amp;i.;
	                call symputx('name',SAS_name);
					call symputx('plan',substr(SAS_name,5,3));
	        run;
				%put "&amp;amp;name.";
				%put "&amp;amp;plan.";


%macro renameVars(tbl,infmt_stdz);
  %local lib;
  %let lib=%upcase(%scan(WORK.&amp;amp;name.,-2,.));
  %let tbl=%upcase(%scan(&amp;amp;tbl,-1,.));

  %local rename_vars;
  %let rename_vars=;
  proc sql noprint;
    select cats(name,'=',input(name,$&amp;amp;infmt_stdz.32.)) 
      into :rename_vars separated by ' '
    from dictionary.columns
    where 
      libname="&amp;amp;lib" 
      and memname="&amp;amp;tbl"
      and not missing(input(name,$&amp;amp;infmt_stdz.32.))
    ;
  quit;
  
  %if %nrbquote(&amp;amp;rename_vars) ne %nrbquote() %then
    %do;
      proc datasets lib=&amp;amp;lib nolist;
        modify &amp;amp;tbl;
          rename &amp;amp;rename_vars;
        run;
      quit;
    %end;
%mend;

			data &amp;amp;name. (drop=start_date end_date);
				set outdta.&amp;amp;name.;

				/* Create plan name */
				Plan="&amp;amp;plan.";
/*				Plan_LName=put(plan, $Plan_Abbrev.);*/

/*				/* Format date variables */*/;
				StartDate=input(start_date, yymmdd10.);
				EndDate=input(end_date, yymmdd10.);

				format StartDate EndDate mmddyy10. plan $4.;

			   rc=dosubl(cats('%renameVars(',&amp;amp;name.,',',varname_stdz,');'));

			run;



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Ok, so here's what I have so far but it's not working. I'm not sure where I'm messing up. The result is an error message: "syntax error, expecting one of the following: ), -.. The symbol is not recognized and will be ignored.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jun 2020 01:13:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663777#M198216</guid>
      <dc:creator>A_Swoosh</dc:creator>
      <dc:date>2020-06-21T01:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the name of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663790#M198225</link>
      <description>&lt;P&gt;Looking at your code I find it a bit hard to understand what you're trying to do so here just a few remarks.&lt;/P&gt;
&lt;P&gt;1. You've got two %macro statements but only a single %mend&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. You seem to misunderstand how the macro I've posted works. You only call the macro ONCE per table. A rename operates against the descriptor portion ("the header") of a table and not against the data portion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please share how table "SASFILES" looks like? May be post a print of a few rows.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jun 2020 03:41:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663790#M198225</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-21T03:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the name of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663792#M198227</link>
      <description>&lt;P&gt;SASfiles is my way to call all my datasets; it looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Filename
Data1
Data2
Data3
Data4
...
Data16&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2. Yea, I don't think I'm following that aspect of it.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jun 2020 04:26:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663792#M198227</guid>
      <dc:creator>A_Swoosh</dc:creator>
      <dc:date>2020-06-21T04:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the name of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663795#M198229</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/197542"&gt;@A_Swoosh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;SASfiles is my way to call all my datasets; it looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Filename
Data1
Data2
Data3
Data4
...
Data16&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2. Yea, I don't think I'm following that aspect of it.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To call the macro for a specific table in work would look like:&lt;/P&gt;
&lt;PRE&gt;%renameVars(work.mytable,varname_stdz);&lt;/PRE&gt;
&lt;P&gt;If you've got a SAS table with the table names (your table "sasfiles") then here how you can call the macro once per observation.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set sasfiles;
  rc=dosubl( cats('%renameVars(',filename,',varname_stdz);') );
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;N.B: Make sure that the value of your variable &lt;EM&gt;Filename&lt;/EM&gt; contains &amp;lt;libref&amp;gt;.&amp;lt;table name&amp;gt;. If you omit the libref then the macro will look in WORK.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 01:16:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-name-of-variables/m-p/663795#M198229</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-24T01:16:15Z</dc:date>
    </item>
  </channel>
</rss>

