<?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: macro variabl a in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-value-as-observation-value-in-a-new-column-proc/m-p/621336#M182659</link>
    <description>&lt;P&gt;Forget whether you have a macro variable or not and write the SAS code you want for one case.&amp;nbsp; Make sure the SAS code works (not sure your posted code will work at all so this is key) before trying to use macro variables and/or macro logic to generate the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to reference a numeric value?&amp;nbsp; For example if you are just trying to run code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select 0.20 as power&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and you have a macro variable named FRED that has the value 0.20 then just replace the text with the reference to the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select &amp;amp;fred as power&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if you are trying to generate a character variable then your SAS code probably looks like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select "CompanyA" as company&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;now in that case if your macro variable SAM has the value CompanyA then you need to keep the quotes. And they need to be double quote characters and not single quote (aka apostrophe) characters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select "&amp;amp;sam" as company&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because macro triggers like &amp;amp; and % are ignored inside of strings bounded by single quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jan 2020 23:09:47 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-01-30T23:09:47Z</dc:date>
    <item>
      <title>macro variable value as observation value in a new column proc sql create table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-value-as-observation-value-in-a-new-column-proc/m-p/621334#M182658</link>
      <description>&lt;P&gt;I have a macro variable that I would like to use as the observation values in a new column in a proc sql table.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The macro variable is &amp;amp;_size, and group&amp;amp;size and above&amp;amp;size are columns in the table 'mydata'.&amp;nbsp; the proc sql creates two columns, and I want a third that has the same value which is the macro variable value.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in a normal proc sql, i would put:&amp;nbsp; &amp;nbsp;' ' as new-column,&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;But in a macro, I don't know how to do this.&amp;nbsp; I don't use macros much.&amp;nbsp; below it is&amp;nbsp; &amp;nbsp;???&amp;amp;_size as mySize .&amp;nbsp; I have tried with single quotes also.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is what I pass into the macro (which works great without my attempt at creating the new column based on the macro variable:&lt;/P&gt;&lt;P&gt;%sizeEval( sizeLevel=1500, _size=_15 );&lt;/P&gt;&lt;P&gt;Here is the opening of the macro:&lt;/P&gt;&lt;P&gt;%macro sizeEval(sizeLevel=, _size=);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my proc sql in the macro:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;create table sustained&amp;amp;_size as&lt;BR /&gt;select distinct size, seconds, count(distinct group&amp;amp;_size) as count&amp;amp;_size,&lt;BR /&gt;from (select &lt;STRONG&gt;???&amp;amp;_size as mySize&lt;/STRONG&gt;, distinct max(above&amp;amp;_size) as seconds, group&amp;amp;_size&lt;BR /&gt;from mydata&lt;BR /&gt;where above&amp;amp;_size ^= 0&lt;BR /&gt;group by group&amp;amp;_size)&lt;BR /&gt;group by seconds, &lt;STRONG&gt;size&lt;/STRONG&gt;&lt;BR /&gt;order by seconds&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 30 Jan 2020 23:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-value-as-observation-value-in-a-new-column-proc/m-p/621334#M182658</guid>
      <dc:creator>yelkenli</dc:creator>
      <dc:date>2020-01-30T23:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: macro variabl a</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-value-as-observation-value-in-a-new-column-proc/m-p/621336#M182659</link>
      <description>&lt;P&gt;Forget whether you have a macro variable or not and write the SAS code you want for one case.&amp;nbsp; Make sure the SAS code works (not sure your posted code will work at all so this is key) before trying to use macro variables and/or macro logic to generate the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to reference a numeric value?&amp;nbsp; For example if you are just trying to run code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select 0.20 as power&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and you have a macro variable named FRED that has the value 0.20 then just replace the text with the reference to the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select &amp;amp;fred as power&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if you are trying to generate a character variable then your SAS code probably looks like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select "CompanyA" as company&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;now in that case if your macro variable SAM has the value CompanyA then you need to keep the quotes. And they need to be double quote characters and not single quote (aka apostrophe) characters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select "&amp;amp;sam" as company&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because macro triggers like &amp;amp; and % are ignored inside of strings bounded by single quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 23:09:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-value-as-observation-value-in-a-new-column-proc/m-p/621336#M182659</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-30T23:09:47Z</dc:date>
    </item>
  </channel>
</rss>

