<?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: Creating new column with Macro Variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-column-with-Macro-Variables/m-p/210476#M52074</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You may be having issues with&lt;/P&gt;&lt;P&gt;%let sas_name=%scan(&amp;amp;sas_name_list, &amp;amp;1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would expect an error as &amp;amp;1 (digit 1) is not valid for a macro variable name. I suspect that you mean &amp;amp;l.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also this line&lt;/P&gt;&lt;P&gt;Select *, &amp;amp;location_name as loc_name&lt;/P&gt;&lt;P&gt;if you want to assign the text value of the macro variable location_name should be&lt;/P&gt;&lt;P&gt;Select *, "&amp;amp;location_name" as loc_name&lt;/P&gt;&lt;P&gt;if you want to assign the same value to every instance of loc_name in the output.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;ERROR: The following columns were not found in the contributing tables&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;is because with the "" around the macro variable SAS is looking for a variable named London whose values would be assigned to loc_name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It might help to provide a small example starting data set and what you expect the output to be.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Trying to ADD variables to an EXISTING data set really should use the ALTER TABLE statement instead of CREATE TABLE.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 06 May 2015 19:53:49 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2015-05-06T19:53:49Z</dc:date>
    <item>
      <title>Creating new column with Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-column-with-Macro-Variables/m-p/210475#M52073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to create a new column with using macro variables which were created by the beginning of program. But the macro variable doesn't show up as variable I assigned. It comes with "&amp;amp;location_name'&lt;/P&gt;&lt;P&gt;Or it gives me an error &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;ERROR: The following columns were not found in the contributing tables&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a code I used...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data location;&lt;/P&gt;&lt;P&gt;id=1; location_name='London'; sas_name='qqq'; output;&lt;/P&gt;&lt;P&gt;id=1; location_name='New York'; sas_name='www'; output;&lt;/P&gt;&lt;P&gt;id=1; location_name='Tokyo'; sas_name='eee'; output; &lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;.....................&lt;/P&gt;&lt;P&gt;..............................&lt;/P&gt;&lt;P&gt;%macro process;&lt;/P&gt;&lt;P&gt;%let I=1;&lt;/P&gt;&lt;P&gt;%let sas_name=%scan(&amp;amp;sas_name_list, &amp;amp;1);&lt;/P&gt;&lt;P&gt;%let location_name=%scan(&amp;amp;location_name_list, &amp;amp;1);&lt;/P&gt;&lt;P&gt;%do %until(&amp;amp;sas_name= );&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc SQL;&lt;/P&gt;&lt;P&gt;Create table &amp;amp;sas_name as&lt;/P&gt;&lt;P&gt;Select *, &amp;amp;location_name as loc_name&lt;/P&gt;&lt;P&gt;from work.&amp;amp;sas_name;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let I=%val(&amp;amp;I +1);&lt;/P&gt;&lt;P&gt;%let sas_name = %scan(&amp;amp;sas_name_list, &amp;amp;I);&lt;/P&gt;&lt;P&gt;%let location_name = %scan(&amp;amp;location_name_list, &amp;amp;I);&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%process;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please let me know if anything is unclear and thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;amp;location_name as loc_name&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 May 2015 19:42:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-column-with-Macro-Variables/m-p/210475#M52073</guid>
      <dc:creator>JUN_Sands</dc:creator>
      <dc:date>2015-05-06T19:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new column with Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-column-with-Macro-Variables/m-p/210476#M52074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You may be having issues with&lt;/P&gt;&lt;P&gt;%let sas_name=%scan(&amp;amp;sas_name_list, &amp;amp;1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would expect an error as &amp;amp;1 (digit 1) is not valid for a macro variable name. I suspect that you mean &amp;amp;l.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also this line&lt;/P&gt;&lt;P&gt;Select *, &amp;amp;location_name as loc_name&lt;/P&gt;&lt;P&gt;if you want to assign the text value of the macro variable location_name should be&lt;/P&gt;&lt;P&gt;Select *, "&amp;amp;location_name" as loc_name&lt;/P&gt;&lt;P&gt;if you want to assign the same value to every instance of loc_name in the output.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;ERROR: The following columns were not found in the contributing tables&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;is because with the "" around the macro variable SAS is looking for a variable named London whose values would be assigned to loc_name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It might help to provide a small example starting data set and what you expect the output to be.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Trying to ADD variables to an EXISTING data set really should use the ALTER TABLE statement instead of CREATE TABLE.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 May 2015 19:53:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-column-with-Macro-Variables/m-p/210476#M52074</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-05-06T19:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new column with Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-column-with-Macro-Variables/m-p/210477#M52075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ballardw,&lt;/P&gt;&lt;P&gt;'Alter Table' resolved the issue. Thanks so much !&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 May 2015 20:11:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-column-with-Macro-Variables/m-p/210477#M52075</guid>
      <dc:creator>JUN_Sands</dc:creator>
      <dc:date>2015-05-06T20:11:32Z</dc:date>
    </item>
  </channel>
</rss>

