<?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: SELECT INTO WITHIN DO LOOP AND MACRO VARIABLE in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/SELECT-INTO-WITHIN-DO-LOOP-AND-MACRO-VARIABLE/m-p/537620#M6796</link>
    <description>&lt;P&gt;Its not entirely clear to me what you are trying to achieve.&amp;nbsp; From that snippet of code, it looks like you are taking one item from a dataset, and then putting that into a macro variable, which you are then inserting into a dataset?&amp;nbsp; This really can't be the best way to achieve your end result.&amp;nbsp; SAS provides much functionality for merging, setting, updating data, so why try to code it by hand?&amp;nbsp; Just from what I can see there (and you have not provided any test data/required output so its just guess work);&lt;/P&gt;
&lt;PRE&gt;data test;
  merge  master dep_rate_data_0002 (where=(account="&amp;amp;v1.") keep=beta_up);
run;&lt;/PRE&gt;
&lt;P&gt;Should work, or if the variable exists, use update or sql insert.&amp;nbsp; Plenty of options.&amp;nbsp; Avoid using global macro variables, its bad practice and can lead to very hard to debug issues (as global affects the whole session).&lt;/P&gt;</description>
    <pubDate>Fri, 22 Feb 2019 08:29:39 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2019-02-22T08:29:39Z</dc:date>
    <item>
      <title>SELECT INTO WITHIN DO LOOP AND MACRO VARIABLE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SELECT-INTO-WITHIN-DO-LOOP-AND-MACRO-VARIABLE/m-p/537555#M6787</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to execute the following code. I am try to get store different value of beta because it varies across A, B, and C. It does not give me updated value of beta.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let prod = A B C;&lt;/P&gt;&lt;P&gt;%LET ns =&amp;nbsp;%sysfunc(countw(&amp;amp;prod.));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro lookup_table;&lt;BR /&gt;%GLOBAL beta_up_&amp;amp;i. ;&lt;BR /&gt;%local i v1;&lt;BR /&gt;%do i=1 %to &amp;amp;ns.;&lt;BR /&gt;%let v1 = %scan(&amp;amp;prod, &amp;amp;i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select beta_up into :&lt;FONT color="#FF0000"&gt;beta_up_&amp;amp;v1.&lt;/FONT&gt;&lt;BR /&gt;from WORK.DEP_RATE_DATA_0002(where=( Account = "&amp;amp;v1"));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;set master;&lt;/P&gt;&lt;P&gt;variable_want =&amp;nbsp;&lt;FONT color="#FF0000"&gt;&amp;amp;&amp;amp;beta_up_&amp;amp;v1.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%lookup_table;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%put &lt;FONT color="#FF0000"&gt;&amp;amp;&amp;amp;beta_up_&amp;amp;v1.&lt;/FONT&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And when I try to check the value of &amp;amp;&amp;amp;beta_up_&amp;amp;v1.; it gave me error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference V1 not resolved.&lt;BR /&gt;ERROR: Invalid symbolic variable name &amp;amp;.&lt;BR /&gt;ERROR: Symbolic variable name V1. must contain only letters, digits, and underscores.&lt;BR /&gt;ERROR: Invalid symbolic variable name V1..&lt;BR /&gt;WARNING: Apparent symbolic reference V1 not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference V1 not resolved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please help me out? Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 22:32:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SELECT-INTO-WITHIN-DO-LOOP-AND-MACRO-VARIABLE/m-p/537555#M6787</guid>
      <dc:creator>tampham92</dc:creator>
      <dc:date>2019-02-21T22:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT INTO WITHIN DO LOOP AND MACRO VARIABLE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SELECT-INTO-WITHIN-DO-LOOP-AND-MACRO-VARIABLE/m-p/537558#M6788</link>
      <description>Scope, your global declaration is before the i is declared so the macro variables are not created in the global table. Move it into your loop.</description>
      <pubDate>Thu, 21 Feb 2019 22:41:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SELECT-INTO-WITHIN-DO-LOOP-AND-MACRO-VARIABLE/m-p/537558#M6788</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-21T22:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT INTO WITHIN DO LOOP AND MACRO VARIABLE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SELECT-INTO-WITHIN-DO-LOOP-AND-MACRO-VARIABLE/m-p/537562#M6789</link>
      <description>&lt;P&gt;This won't work though:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;

set master;

variable_want =&amp;nbsp;&amp;amp;&amp;amp;beta_up_&amp;amp;v1.;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're always starting from the 'master' table and your test data will overwrite it each time. So you'll only be left with the results from the last loop, not all the results.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/176468"&gt;@tampham92&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to execute the following code. I am try to get store different value of beta because it varies across A, B, and C. It does not give me updated value of beta.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let prod = A B C;&lt;/P&gt;
&lt;P&gt;%LET ns =&amp;nbsp;%sysfunc(countw(&amp;amp;prod.));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro lookup_table;&lt;BR /&gt;%GLOBAL beta_up_&amp;amp;i. ;&lt;BR /&gt;%local i v1;&lt;BR /&gt;%do i=1 %to &amp;amp;ns.;&lt;BR /&gt;%let v1 = %scan(&amp;amp;prod, &amp;amp;i);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select beta_up into :&lt;FONT color="#FF0000"&gt;beta_up_&amp;amp;v1.&lt;/FONT&gt;&lt;BR /&gt;from WORK.DEP_RATE_DATA_0002(where=( Account = "&amp;amp;v1"));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;/P&gt;
&lt;P&gt;set master;&lt;/P&gt;
&lt;P&gt;variable_want =&amp;nbsp;&lt;FONT color="#FF0000"&gt;&amp;amp;&amp;amp;beta_up_&amp;amp;v1.;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%lookup_table;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &lt;FONT color="#FF0000"&gt;&amp;amp;&amp;amp;beta_up_&amp;amp;v1.&lt;/FONT&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And when I try to check the value of &amp;amp;&amp;amp;beta_up_&amp;amp;v1.; it gave me error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WARNING: Apparent symbolic reference V1 not resolved.&lt;BR /&gt;ERROR: Invalid symbolic variable name &amp;amp;.&lt;BR /&gt;ERROR: Symbolic variable name V1. must contain only letters, digits, and underscores.&lt;BR /&gt;ERROR: Invalid symbolic variable name V1..&lt;BR /&gt;WARNING: Apparent symbolic reference V1 not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference V1 not resolved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please help me out? Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 23:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SELECT-INTO-WITHIN-DO-LOOP-AND-MACRO-VARIABLE/m-p/537562#M6789</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-21T23:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT INTO WITHIN DO LOOP AND MACRO VARIABLE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SELECT-INTO-WITHIN-DO-LOOP-AND-MACRO-VARIABLE/m-p/537620#M6796</link>
      <description>&lt;P&gt;Its not entirely clear to me what you are trying to achieve.&amp;nbsp; From that snippet of code, it looks like you are taking one item from a dataset, and then putting that into a macro variable, which you are then inserting into a dataset?&amp;nbsp; This really can't be the best way to achieve your end result.&amp;nbsp; SAS provides much functionality for merging, setting, updating data, so why try to code it by hand?&amp;nbsp; Just from what I can see there (and you have not provided any test data/required output so its just guess work);&lt;/P&gt;
&lt;PRE&gt;data test;
  merge  master dep_rate_data_0002 (where=(account="&amp;amp;v1.") keep=beta_up);
run;&lt;/PRE&gt;
&lt;P&gt;Should work, or if the variable exists, use update or sql insert.&amp;nbsp; Plenty of options.&amp;nbsp; Avoid using global macro variables, its bad practice and can lead to very hard to debug issues (as global affects the whole session).&lt;/P&gt;</description>
      <pubDate>Fri, 22 Feb 2019 08:29:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SELECT-INTO-WITHIN-DO-LOOP-AND-MACRO-VARIABLE/m-p/537620#M6796</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-22T08:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT INTO WITHIN DO LOOP AND MACRO VARIABLE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SELECT-INTO-WITHIN-DO-LOOP-AND-MACRO-VARIABLE/m-p/537721#M6807</link>
      <description>&lt;P&gt;I moved the Global statement into the loop and it ran. However, when I tried to test where the value is store using %put statement (%put &amp;amp;beta_up&amp;amp;v1) it just returned&amp;nbsp;beta_up&amp;amp;v1. Do you know why?;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Feb 2019 15:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SELECT-INTO-WITHIN-DO-LOOP-AND-MACRO-VARIABLE/m-p/537721#M6807</guid>
      <dc:creator>tampham92</dc:creator>
      <dc:date>2019-02-22T15:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT INTO WITHIN DO LOOP AND MACRO VARIABLE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SELECT-INTO-WITHIN-DO-LOOP-AND-MACRO-VARIABLE/m-p/537741#M6808</link>
      <description>&lt;P&gt;You need more &amp;amp; in front of it. You had it correct in your initial post but in the code below you only have one.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let v1=A;
%let beta_upA = Testing;

*wrong;
%put &amp;amp;beta_up&amp;amp;v1;
*right;
%put &amp;amp;&amp;amp;beta_up&amp;amp;v1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/176468"&gt;@tampham92&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I moved the Global statement into the loop and it ran. However, when I tried to test where the value is store using %put statement (%put &lt;FONT size="4" color="#FF0000"&gt;&lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;&lt;/FONT&gt;beta_up&amp;amp;v1) it just returned&amp;nbsp;beta_up&amp;amp;v1. Do you know why?;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Feb 2019 16:12:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SELECT-INTO-WITHIN-DO-LOOP-AND-MACRO-VARIABLE/m-p/537741#M6808</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-22T16:12:20Z</dc:date>
    </item>
  </channel>
</rss>

