<?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: %let statement with value from table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/let-statement-with-value-from-table/m-p/777923#M247588</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393967"&gt;@vicmaria98&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is there a way to do something like the below?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let x = &amp;amp;Table.x;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to assign the macro variable to the value that is found in the Table. I cannot use proc sql no print as I am doing this in a datastep.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Use the CALL SYMPUTX() function to create a macro variable from a data step.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set table;
  call symputx('x',x);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But remember that if you need to use that macro variable in the same data step you will need to use the SYMGET() or SYMGETN() to retrieve the value.&amp;nbsp; If you just reference the macro variable with &amp;amp;X that reference will be resolved BEFORE the data step is compiled and so definitely before the CALL SYMPUTX() function call can execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do need to use the value within the same data step then just leave the value in a data step variable instead of converting it to text to store into a macro variable and then back from text to a variable.&amp;nbsp; Note that you could use a variable that is not written to the output dataset(s).&amp;nbsp; If you need to prevent the data step from setting the variable to missing when it starts its next iteration then use the RETAIN statement.&lt;/P&gt;</description>
    <pubDate>Tue, 02 Nov 2021 14:11:21 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-11-02T14:11:21Z</dc:date>
    <item>
      <title>%let statement with value from table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-statement-with-value-from-table/m-p/777915#M247584</link>
      <description>&lt;P&gt;Is there a way to do something like the below?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let x = &amp;amp;Table.x;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to assign the macro variable to the value that is found in the Table. I cannot use proc sql no print as I am doing this in a datastep.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2021 13:43:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-statement-with-value-from-table/m-p/777915#M247584</guid>
      <dc:creator>vicmaria98</dc:creator>
      <dc:date>2021-11-02T13:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: %let statement with value from table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-statement-with-value-from-table/m-p/777916#M247585</link>
      <description>&lt;P&gt;Use the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p1fa0ay5pzr9yun1mvqxv8ipzd4d.htm" target="_self"&gt;Call Symputx Routine&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   x = 100;
   
   call symputx('x', x);
run;

%put &amp;amp;x.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Nov 2021 13:52:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-statement-with-value-from-table/m-p/777916#M247585</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-11-02T13:52:28Z</dc:date>
    </item>
    <item>
      <title>Re: %let statement with value from table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-statement-with-value-from-table/m-p/777917#M247586</link>
      <description>&lt;P&gt;To set a macro variable from dataset values, you either need PROC SQL with SELECT INTO, or a DATA step with CALL SYMPUT/CALL SYMPUTX.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2021 13:50:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-statement-with-value-from-table/m-p/777917#M247586</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-02T13:50:22Z</dc:date>
    </item>
    <item>
      <title>Re: %let statement with value from table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-statement-with-value-from-table/m-p/777923#M247588</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393967"&gt;@vicmaria98&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is there a way to do something like the below?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let x = &amp;amp;Table.x;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to assign the macro variable to the value that is found in the Table. I cannot use proc sql no print as I am doing this in a datastep.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Use the CALL SYMPUTX() function to create a macro variable from a data step.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set table;
  call symputx('x',x);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But remember that if you need to use that macro variable in the same data step you will need to use the SYMGET() or SYMGETN() to retrieve the value.&amp;nbsp; If you just reference the macro variable with &amp;amp;X that reference will be resolved BEFORE the data step is compiled and so definitely before the CALL SYMPUTX() function call can execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do need to use the value within the same data step then just leave the value in a data step variable instead of converting it to text to store into a macro variable and then back from text to a variable.&amp;nbsp; Note that you could use a variable that is not written to the output dataset(s).&amp;nbsp; If you need to prevent the data step from setting the variable to missing when it starts its next iteration then use the RETAIN statement.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2021 14:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-statement-with-value-from-table/m-p/777923#M247588</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-02T14:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: %let statement with value from table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-statement-with-value-from-table/m-p/777948#M247598</link>
      <description>&lt;P&gt;I'm just fooling around but you could "resolve" this problem with %let statement too &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table;
  x = 42;
run;

data _null_;
  set table;
  rc = resolve('%let x = ' || put(x, best32.) || ';');
run;

%put &amp;amp;=x.;&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;B-)&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2021 15:57:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-statement-with-value-from-table/m-p/777948#M247598</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-11-02T15:57:18Z</dc:date>
    </item>
  </channel>
</rss>

