<?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 Proc SQL, macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-macro-variable/m-p/423750#M104246</link>
    <description>&lt;P&gt;I have a question on a Proc SQL code using a macro variable. The below code is selecting a macro variable as PRD_END_DT. I do not understand how the code can be selecting a macro variable, I have not seen syntax like this before. Any help is appreciated, to help me understand. Also, I do not understand why this is selecting 'ACH', how can this be referring to selecting a column in out.Represent_data_ACH_V3&amp;amp;Ext? I am trying to understand this code and could not find anything in search results similar to this. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
		create table out.Represent_ACH_grouped&amp;amp;Ext as		
select &amp;amp;EndPeriod. as PRD_END_DT,'ACH' as Channel,represent_group, count(*) as items
from out.Represent_data_ACH_V3&amp;amp;Ext
		group by 3;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Dec 2017 16:45:27 GMT</pubDate>
    <dc:creator>perkinsb2</dc:creator>
    <dc:date>2017-12-27T16:45:27Z</dc:date>
    <item>
      <title>Proc SQL, macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-macro-variable/m-p/423750#M104246</link>
      <description>&lt;P&gt;I have a question on a Proc SQL code using a macro variable. The below code is selecting a macro variable as PRD_END_DT. I do not understand how the code can be selecting a macro variable, I have not seen syntax like this before. Any help is appreciated, to help me understand. Also, I do not understand why this is selecting 'ACH', how can this be referring to selecting a column in out.Represent_data_ACH_V3&amp;amp;Ext? I am trying to understand this code and could not find anything in search results similar to this. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
		create table out.Represent_ACH_grouped&amp;amp;Ext as		
select &amp;amp;EndPeriod. as PRD_END_DT,'ACH' as Channel,represent_group, count(*) as items
from out.Represent_data_ACH_V3&amp;amp;Ext
		group by 3;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Dec 2017 16:45:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-macro-variable/m-p/423750#M104246</guid>
      <dc:creator>perkinsb2</dc:creator>
      <dc:date>2017-12-27T16:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL, macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-macro-variable/m-p/423753#M104247</link>
      <description>&lt;P&gt;The macro variables must have a value assigned to them before you run PROC SQL. Then, all the macro processor does is replace the macro variable name with the value assigned to it when your run PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, for example, &amp;amp;endperiod has to have a value prior to SQL, let's say it's value is VAR22, and so VAR22 is used where &amp;amp;endperiod appears in the code.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Dec 2017 16:59:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-macro-variable/m-p/423753#M104247</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-12-27T16:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL, macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-macro-variable/m-p/423754#M104248</link>
      <description>&lt;P&gt;Macro variables resolve to text, i.e. SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you submit:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;=EndPeriod;
%put &amp;amp;=Ext;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it will print the resolved values of those two variables to the log.&amp;nbsp; What do you see in the log when you run that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's suppose that&amp;nbsp;you have macro variables like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;6    %let EndPeriod="27Dec2017"d;
7    %let Ext=Production;
8
9    %put &amp;amp;=EndPeriod;
ENDPERIOD="27Dec2017"d
10   %put &amp;amp;=Ext;
EXT=Production
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then when the macro variables resolve, your SQL code would be like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table out.Represent_ACH_groupedProduction as
    select
      "27Dec2017"d as PRD_END_DT
      ,'ACH' as Channel
      ,represent_group
      ,count(*) as items
    from out.Represent_data_ACH_V3Production
    group by 3
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That is valid PROC SQL code (or at least looks like it, I didn't run it).&amp;nbsp; On the select statement you can put literal values in addition to column names.&amp;nbsp; So 'ACH' as Channel puts the character string ACH into the column Channel.&amp;nbsp; "27Dec2017"d as PRD_END_DT puts the numeric value 21180 (which is the SAS date for Dec 27, 2017) into the column PRD_END_DT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Dec 2017 17:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-macro-variable/m-p/423754#M104248</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-12-27T17:00:04Z</dc:date>
    </item>
  </channel>
</rss>

