<?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: Change Varaible Names with Macro in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Change-Varaible-Names-with-Macro/m-p/574245#M12662</link>
    <description>I only have a dataset with the q7_16 variables. Not one with the actual words</description>
    <pubDate>Wed, 17 Jul 2019 15:56:30 GMT</pubDate>
    <dc:creator>A_Halps</dc:creator>
    <dc:date>2019-07-17T15:56:30Z</dc:date>
    <item>
      <title>Change Varaible Names with Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Change-Varaible-Names-with-Macro/m-p/574235#M12658</link>
      <description>&lt;P&gt;I am trying to change the names of certain variables with a macro because I have many different variables.&lt;/P&gt;&lt;P&gt;So, I need q7_16 = Mild, q7_17 = Moderate,&amp;nbsp;q7_18 = Severe,&amp;nbsp;q7_19 = As_bad, q7_2094 = No_wheeze, and q7_2095 = Wheeze_whistle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have tried, but I can't seem to change all of the variables. It will only change the last one.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro question (ans_num, answer, label);
proc sql; 
	create table severity_lrd_v3b_names as 
		select *, 
			q7_&amp;amp;ans_num as &amp;amp;answer label &amp;amp;label
			from severity_lrd_v3b;
quit;
%mend; 
%question (16, Mild, 'Mild');
%question (17, Moderate, 'Moderate');
%question (18, Severe, 'Severe');
%question (19, As_bad, 'As_bad');
%question (2094,No_wheeze, 'No_wheeze');
%question (19, Wheeze_whistle, 'Wheeze_whistle');  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jul 2019 15:45:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Change-Varaible-Names-with-Macro/m-p/574235#M12658</guid>
      <dc:creator>A_Halps</dc:creator>
      <dc:date>2019-07-17T15:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Change Varaible Names with Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Change-Varaible-Names-with-Macro/m-p/574244#M12661</link>
      <description>Do you have a data set that has the old and new names? If you do, or can create that one, I have a macro you can use here, it's super efficient because it uses PROC DATASETS. Your code above doesn't work, because each time you're starting from severity_lrd_v3b which does not have the previous runs changes so you'll only see the results of the last macro call.</description>
      <pubDate>Wed, 17 Jul 2019 15:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Change-Varaible-Names-with-Macro/m-p/574244#M12661</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-17T15:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Change Varaible Names with Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Change-Varaible-Names-with-Macro/m-p/574245#M12662</link>
      <description>I only have a dataset with the q7_16 variables. Not one with the actual words</description>
      <pubDate>Wed, 17 Jul 2019 15:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Change-Varaible-Names-with-Macro/m-p/574245#M12662</guid>
      <dc:creator>A_Halps</dc:creator>
      <dc:date>2019-07-17T15:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Change Varaible Names with Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Change-Varaible-Names-with-Macro/m-p/574250#M12665</link>
      <description>Can you make one? Seems easier than macro calls but ultimately your choice. &lt;BR /&gt;&lt;BR /&gt;If you want to fix your macro above you just need to change the data set name as I mentioned previously so it's re-using the same data set each time so it adds to it instead of using the original data set.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 17 Jul 2019 15:59:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Change-Varaible-Names-with-Macro/m-p/574250#M12665</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-17T15:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: Change Varaible Names with Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Change-Varaible-Names-with-Macro/m-p/574254#M12666</link>
      <description>&lt;P&gt;Only the last call has any effect because you keep re-reading the original dataset.&lt;/P&gt;
&lt;P&gt;The easiest change might be to make the macro just generate part of the SQL code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro question (ans_num, answer, label);
q7_&amp;amp;ans_num as &amp;amp;answer label &amp;amp;label

%mend; 
proc sql; 
  create table severity_lrd_v3b_names as 
    select *
    ,%question (16, Mild, 'Mild')
    ,%question (17, Moderate, 'Moderate')
    ,%question (18, Severe, 'Severe')
    ,%question (19, As_bad, 'As_bad')
    ,%question (2094,No_wheeze, 'No_wheeze')
    ,%question (19, Wheeze_whistle, 'Wheeze_whistle')
    from severity_lrd_v3b
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But of course at that point you should recognize that you don't need the macro at all as it is just as easy to type the actual code as the macro calls.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 16:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Change-Varaible-Names-with-Macro/m-p/574254#M12666</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-17T16:10:54Z</dc:date>
    </item>
  </channel>
</rss>

