<?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: Variable values not changing during data step execution and call execute of macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716843#M221621</link>
    <description>&lt;P&gt;Call Execute argument is a string to submit.&lt;/P&gt;
&lt;P&gt;Suppose cmttblname = "Table1" then the submitted string is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%tstuniqvalid(Table1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 04 Feb 2021 16:43:53 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2021-02-04T16:43:53Z</dc:date>
    <item>
      <title>Variable values not changing during data step execution and call execute of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716506#M221452</link>
      <description>&lt;P&gt;Hi I have written som code to go through a table of tablenames and take each tablename and put it in to a sql statement in a macro.&amp;nbsp; There are 2 table names in the table the first table name is read in and put into the WHERE clause and according to debug the value does change to the 2nd table name but the macro always keeps the first table name.&amp;nbsp; &amp;nbsp;Can you help me figure out why?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the data step:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_/debug;
	set dbtblnames_complete;
	%put  &amp;amp;newtblname1;
	%let  crnttblname = &amp;amp;newtblname1;
	%put &amp;amp;crnttblname;
	call execute('%nrstr(%%tstuniqvalid(&amp;amp;newtblname1));');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here is the macro that gets called:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro tstuniqvalid(crnttblname);
proc sql;

connect to teradata as eiwp (username=&amp;amp;xxxuser. password=&amp;amp;xxxpass. tdpid=&amp;amp;xxxx_TDPID. mode=teradata fastload=yes);
create table unique_validcustid as
select count(*) from connection to eiwp (
select  hist_ky_add
		,count(*)
from (select cast(cust_id as decimal(15,0)) as cust_id_test
	,cust_id
	,cust_id_type
	,cell_ky
	,rank(cust_id || cust_id_type || cast(cell_ky as varchar(16))asc)as hist_ky_add
from &amp;amp;crnttblname) a
group by 1
having count(*) &amp;gt; 1
);
%put "SQL Return code and message" &amp;amp;sqlxrc &amp;amp;SQLXMSG;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;According to the debug the variable&amp;nbsp;newtblname1&amp;nbsp; is getting changed&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;gt; go
&lt;STRONG&gt;newtblname1&lt;/STRONG&gt; = dbname.table1
Old value =
Value changed at line 8964 column 5
Stepped to line 8968 column 5
&amp;gt; go
newtblname1 = dbname.table2
Old value = dbname.table1
Value changed at line 8964 column 5
&amp;gt; go
newtblname1 =
Old value = dbname.table2
Value changed at line 8964 column 5
&amp;gt; go&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but each iteration has the first table name (&lt;CODE class=" language-sas"&gt;dbname.table1)&amp;nbsp;only.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;I can't figure out why. Please take a look and advise. Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 15:59:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716506#M221452</guid>
      <dc:creator>Gayle</dc:creator>
      <dc:date>2021-02-03T15:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: Variable values not changing during data step execution and call execute of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716512#M221455</link>
      <description>&lt;P&gt;You seem confused about the order of execution of macro code, data steps and code pushed to be executed by CALL EXECUTE.&amp;nbsp; Also since this data step is not doing anything with any data why would you want to try to use the data step debugger with it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the data step is not doing anything with the data from dbtblnames_complete the only impact that dataset will have how many times that the data step will iterate. So if it has 3 observations then your first data step is essentially running this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;newtblname1;
%let crnttblname = &amp;amp;newtblname1;
%put &amp;amp;crnttblname;

data _null_;
  call execute('%nrstr(%%tstuniqvalid(&amp;amp;newtblname1));');
  call execute('%nrstr(%%tstuniqvalid(&amp;amp;newtblname1));');
  call execute('%nrstr(%%tstuniqvalid(&amp;amp;newtblname1));');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will result in these three statements being submitted to run after the DATA _NULL_ step finishes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%%tstuniqvalid(&amp;amp;newtblname1);
%%tstuniqvalid(&amp;amp;newtblname1);
%%tstuniqvalid(&amp;amp;newtblname1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Not sure what the impact is of the extra % character there.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 16:10:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716512#M221455</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-03T16:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: Variable values not changing during data step execution and call execute of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716517#M221458</link>
      <description>&lt;P&gt;%LET is not a data step statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming &lt;STRONG&gt;crnttblname&amp;nbsp;&lt;/STRONG&gt;is the variable in &lt;STRONG&gt;dbtblnames_complete&lt;/STRONG&gt; data set&lt;/P&gt;
&lt;P&gt;concatenate it in the&amp;nbsp;&lt;STRONG&gt;call execute&lt;/STRONG&gt; function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_/debug;
 set dbtblnames_complete;
     call execute('%nrstr(%%tstuniqvalid(' || strip(crnttblname) || '));');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Try even:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute('%tstuniqvalid(' || strip(crnttblname) || ');');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Feb 2021 16:27:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716517#M221458</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-03T16:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: Variable values not changing during data step execution and call execute of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716520#M221460</link>
      <description>As mentioned in a previous response, the order of execution is very important to learn. If you have already taken a programming 2 class, i would recommend you take a Macro 1 class too. In the 2-day Macro 1 class, you will learn in detail how macro code gets execute and why the code you are submitting is not the correct way to submit macros. That way you can debug and correct these errors yourself in the future.</description>
      <pubDate>Wed, 03 Feb 2021 16:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716520#M221460</guid>
      <dc:creator>CarmineVerrell</dc:creator>
      <dc:date>2021-02-03T16:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Variable values not changing during data step execution and call execute of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716522#M221461</link>
      <description>&lt;P&gt;This:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_/debug;
	set dbtblnames_complete;
	%put  &amp;amp;newtblname1;
	%let  crnttblname = &amp;amp;newtblname1;
	%put &amp;amp;crnttblname;
	call execute('%nrstr(%%tstuniqvalid(&amp;amp;newtblname1));');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is equivalent to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put  &amp;amp;newtblname1;
%let  crnttblname = &amp;amp;newtblname1;
%put &amp;amp;crnttblname;&lt;BR /&gt;
data _null_/debug;
	set dbtblnames_complete;
	call execute('%nrstr(%%tstuniqvalid(&amp;amp;newtblname1));');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as the macro statements are resolved while the code is being fetched for the data step compiler.&lt;/P&gt;
&lt;P&gt;Since &amp;amp;newtblname1 never changes, all your macro calls will receive the same parameter.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 16:23:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716522#M221461</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-03T16:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Variable values not changing during data step execution and call execute of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716527#M221465</link>
      <description>&lt;P&gt;It looks like you are trying to run a query in Teradata for each table/dataset name that you have in some dataset?&lt;/P&gt;
&lt;P&gt;You seem to be generating a single number from this query?&lt;/P&gt;
&lt;P&gt;Is the goal to start with a dataset like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input tablename :$32. ;
cards;
table1
table2
table3
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And generate a table like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  input tablename :$32.  count ;
cards;
table1 10
table2 0
table3 23456
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Feb 2021 16:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716527#M221465</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-03T16:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: Variable values not changing during data step execution and call execute of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716835#M221614</link>
      <description>&lt;P&gt;Thanks you I am new to SAS programming&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 15:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716835#M221614</guid>
      <dc:creator>Gayle</dc:creator>
      <dc:date>2021-02-04T15:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Variable values not changing during data step execution and call execute of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716837#M221616</link>
      <description>&lt;P&gt;Thanks i will take those courses, right now I am wrapping up the getting started programming course for sas&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 16:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716837#M221616</guid>
      <dc:creator>Gayle</dc:creator>
      <dc:date>2021-02-04T16:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Variable values not changing during data step execution and call execute of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716839#M221618</link>
      <description>&lt;P&gt;thanks , still a bit fuzzy though&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 16:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716839#M221618</guid>
      <dc:creator>Gayle</dc:creator>
      <dc:date>2021-02-04T16:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Variable values not changing during data step execution and call execute of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716840#M221619</link>
      <description>&lt;P&gt;Thank you! concatenating it worked:&amp;nbsp;&lt;STRONG&gt;call execute('%tstuniqvalid(' || strip(crnttblname) || ');');.&amp;nbsp;&lt;/STRONG&gt; I do not really understand why this works yet.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 16:17:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716840#M221619</guid>
      <dc:creator>Gayle</dc:creator>
      <dc:date>2021-02-04T16:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Variable values not changing during data step execution and call execute of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716843#M221621</link>
      <description>&lt;P&gt;Call Execute argument is a string to submit.&lt;/P&gt;
&lt;P&gt;Suppose cmttblname = "Table1" then the submitted string is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%tstuniqvalid(Table1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Feb 2021 16:43:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716843#M221621</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-04T16:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: Variable values not changing during data step execution and call execute of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716910#M221647</link>
      <description>Yes I understand but it only started working when I put the STRIP and concatenated the '. Oh so you mean the parameter has to be in quotes when i do the call execute.</description>
      <pubDate>Thu, 04 Feb 2021 20:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-values-not-changing-during-data-step-execution-and-call/m-p/716910#M221647</guid>
      <dc:creator>Gayle</dc:creator>
      <dc:date>2021-02-04T20:30:21Z</dc:date>
    </item>
  </channel>
</rss>

