<?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: Renaming variable w/ macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Renaming-variable-w-macros/m-p/547269#M151621</link>
    <description>&lt;P&gt;Macro? Not needed. Macro variable? YES!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your problem description isn't entirely clear, you can't rename all of them to prog_name as shown in the example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the general outline of how to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have noprint out=_contents_;
run;
proc sql noprint;
    select cats(name,'=','prog',scan(substr(name,4),1,'_'))
        into :renames separated by ' ' from _contents_
        where name eqt 'prog' and name ? '_ProgramCat_TEXT';
quit;
proc datasets library=work nolist;
    modify have;
    rename &amp;amp;renames;
    delete _contents_;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Mar 2019 21:23:49 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-03-29T21:23:49Z</dc:date>
    <item>
      <title>Renaming variable w/ macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-variable-w-macros/m-p/547264#M151617</link>
      <description>&lt;P&gt;Hi! I'd like to rename variables using a macro-&lt;/P&gt;&lt;P&gt;So I have variables for 1-10 programs and I need to rename them the same name based on their suffix but I need to do the rename given prefix= prog1-prog10.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;Prog1_ProgramCat_TEXT= prog_name&lt;/P&gt;&lt;P&gt;Prog2_ProgramCat_TEXT=prog_name&lt;/P&gt;&lt;P&gt;Prog3_ProgramCat_TEXT=prog_name&lt;/P&gt;&lt;P&gt;.. all the way to the prefix= Prog10_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(All info is contained in variable answers; Please let me know if you need more data info)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;So here's my crazy attempt to make a code for this:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rename(prgname=, prgchall=, prgven=, prgcost=, prgday=, prgdur=, prgdurun=, prgeval=, prgevent=, prgnum=, prgcat=, prgfreq=, prgsite=, prgstart=, prgconsid=);
data programcondensing;

	set WORK.TestExport (keep=agency prog1_: prog2_: prog3_: prog4_: prog5_: prog6_: prog7_: prog8_: prog9_: prog10_: responseid);
		 %rename &amp;amp;prgconsid = prog_considerations
				&amp;amp;prgname= prog_name
				&amp;amp;prgchall = prog_challenges
				&amp;amp;prgven = prog_vendor
				&amp;amp;prgcost= prog_cost
				&amp;amp;prgday = prog_date
				&amp;amp;prgdur = prog_duration
				&amp;amp;prgdurun = prog_duration_unit
				&amp;amp;prgeval = prog_eval
				&amp;amp;prgevent = prog_type
				&amp;amp;prgnum = prog_Num
				&amp;amp;prgcat = prog_cat
				&amp;amp;prgfreq = prog_freq
				&amp;amp;prgsite = prog_site
				&amp;amp;prgstart = prog_start;
			
run;
%mend rename;
options mlogic;

%rename (prgname=:ProgramCat_TEXT, prgchall= :_2, prgven= :_4, prgcost=_5, prgday=:_date_1, prgdur=:_duration, prgdurun=:_durationunit, prgeval=:_evalyesno, prgevent=:_eventtype, prgnum=:_numparticipants, prgcat=:_programcat, prgfreq=:_programfreq, prgsite= :_site_1, prgstart= :_starttime_1, prgconsid=:_1)


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help:)&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2019 17:01:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-variable-w-macros/m-p/547264#M151617</guid>
      <dc:creator>jmmedina25</dc:creator>
      <dc:date>2019-03-29T17:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming variable w/ macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-variable-w-macros/m-p/547269#M151621</link>
      <description>&lt;P&gt;Macro? Not needed. Macro variable? YES!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your problem description isn't entirely clear, you can't rename all of them to prog_name as shown in the example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the general outline of how to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have noprint out=_contents_;
run;
proc sql noprint;
    select cats(name,'=','prog',scan(substr(name,4),1,'_'))
        into :renames separated by ' ' from _contents_
        where name eqt 'prog' and name ? '_ProgramCat_TEXT';
quit;
proc datasets library=work nolist;
    modify have;
    rename &amp;amp;renames;
    delete _contents_;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2019 21:23:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-variable-w-macros/m-p/547269#M151621</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-03-29T21:23:49Z</dc:date>
    </item>
  </channel>
</rss>

