<?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: assign macro variable value to  a new variable, proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816261#M322159</link>
    <description>&lt;P&gt;Add a LENGTH option, for example setting it to 20 characters:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let name=boston;

proc sql;
  create table want as
  select "&amp;amp;name" length = 20 as LOC
         ,Column1
         ,Column2
  from Have
  where ........;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 02 Jun 2022 21:25:09 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2022-06-02T21:25:09Z</dc:date>
    <item>
      <title>assign macro variable value to  a new variable, proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816121#M322094</link>
      <description>&lt;P&gt;There should be easy ways.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"%do i = 1 %to 12;&lt;/P&gt;&lt;P&gt;proc sql; create temp from select&amp;nbsp;&lt;/P&gt;&lt;P&gt;mean(p_&amp;amp;&amp;amp;s&amp;amp;j)&amp;nbsp; as price, ....&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;when the loop ends,&amp;nbsp;&amp;amp;&amp;amp;s&amp;amp;i should have gone through 12 values, say, 12 months. How to insert a new variable, called MONTH, in the same proc sql operation, so the variable price is broken down by MONTH (which contains values of &amp;amp;&amp;amp;s&amp;amp;i)? Thank you&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2022 22:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816121#M322094</guid>
      <dc:creator>fierceanalytics</dc:creator>
      <dc:date>2022-06-01T22:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: assign macro variable value to  a new variable, proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816122#M322095</link>
      <description>&lt;P&gt;Your code base will replace the same data set, Temp, eleven times and only have the result of the last i value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are leaving a LOT out of your problem description, such as where does the macro variable J get assigned, and the &amp;amp;s part of the &amp;amp;&amp;amp;s&amp;amp;j.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your i is supposed to loop through different variables that contain a months values then the data is structured incorrectly for best use in SAS. Generally a separate variable holding the value of month and a single variable with the value works best. That would avoid having to "loop" through anything as then you could process the data "by month" directly..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suggest providing an example of the data in the form of a data step and the desired result.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2022 23:11:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816122#M322095</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-01T23:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: assign macro variable value to  a new variable, proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816123#M322096</link>
      <description>&lt;P&gt;Look for any discrepancies in these two lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%do &lt;STRONG&gt;i&lt;/STRONG&gt; = 1 %to 12;&lt;/P&gt;
&lt;P&gt;mean(p_&amp;amp;&amp;amp;s&lt;STRONG&gt;&amp;amp;j&lt;/STRONG&gt;)&amp;nbsp; as price, .&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2022 23:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816123#M322096</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2022-06-01T23:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: assign macro variable value to  a new variable, proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816124#M322097</link>
      <description>Thank. Let us forget the do loop. I vs. j was just typo.&lt;BR /&gt;&lt;BR /&gt;%let name=boston;&lt;BR /&gt;How to load &amp;amp;name to a new variable called LOC, inside proc sql; alongside getting max, mean… regular sql stuff? Thanks</description>
      <pubDate>Thu, 02 Jun 2022 00:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816124#M322097</guid>
      <dc:creator>fierceanalytics</dc:creator>
      <dc:date>2022-06-02T00:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: assign macro variable value to  a new variable, proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816126#M322099</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let name=boston;

proc sql;
  create table want as
  select "&amp;amp;name" as LOC
         ,Column1
         ,Column2
  from Have
  where ........;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jun 2022 01:12:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816126#M322099</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-06-02T01:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: assign macro variable value to  a new variable, proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816257#M322155</link>
      <description>&lt;P&gt;Thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The next question is : how to regulate length of the new variable LOC? if first pass-through is Boston, LOC gets 6? That works for Huston or Dallas fully, but NY or SF may get truncated? I rephrased my question the second time. You probably sensed this is a do-loop context from my first time of asking with that i and J typo. Thanks. Jia&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 20:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816257#M322155</guid>
      <dc:creator>fierceanalytics</dc:creator>
      <dc:date>2022-06-02T20:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: assign macro variable value to  a new variable, proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816261#M322159</link>
      <description>&lt;P&gt;Add a LENGTH option, for example setting it to 20 characters:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let name=boston;

proc sql;
  create table want as
  select "&amp;amp;name" length = 20 as LOC
         ,Column1
         ,Column2
  from Have
  where ........;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jun 2022 21:25:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816261#M322159</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-06-02T21:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: assign macro variable value to  a new variable, proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816403#M322237</link>
      <description>Good. Thanks</description>
      <pubDate>Fri, 03 Jun 2022 19:35:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-macro-variable-value-to-a-new-variable-proc-sql/m-p/816403#M322237</guid>
      <dc:creator>fierceanalytics</dc:creator>
      <dc:date>2022-06-03T19:35:24Z</dc:date>
    </item>
  </channel>
</rss>

