<?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: Data step question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/717209#M221770</link>
    <description>&lt;P&gt;Hi all, related question for my own knowledge.&amp;nbsp; Is there a downside in using&amp;nbsp;&lt;STRONG&gt;DoSubl&lt;/STRONG&gt;() for the OP's code? My naive opinion is that it would fix the timing.&lt;/P&gt;</description>
    <pubDate>Fri, 05 Feb 2021 20:51:03 GMT</pubDate>
    <dc:creator>PhilC</dc:creator>
    <dc:date>2021-02-05T20:51:03Z</dc:date>
    <item>
      <title>Data step question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/716942#M221660</link>
      <description>&lt;P&gt;from my understanding the data step is like a loop.&amp;nbsp; I have the code below and&amp;nbsp;&lt;CODE class=" language-sas"&gt;dbtblnames_complete has&amp;nbsp;2&amp;nbsp;entries&amp;nbsp;I&amp;nbsp;am&amp;nbsp;getting&amp;nbsp;a&amp;nbsp;different dbms error&amp;nbsp;for&amp;nbsp;each.&amp;nbsp;However&amp;nbsp;the&amp;nbsp;%put&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;statement&amp;nbsp;at&amp;nbsp;the&amp;nbsp;end&amp;nbsp;of&amp;nbsp;the&amp;nbsp;macro(for &lt;STRONG&gt;&amp;amp;sqlxrc &amp;amp;SQLXMSG)&lt;/STRONG&gt;&amp;nbsp;only&amp;nbsp;shows&amp;nbsp;the&amp;nbsp;second&amp;nbsp;error&amp;nbsp;2&amp;nbsp;times.&amp;nbsp;&amp;nbsp;&amp;nbsp;What&amp;nbsp;is&amp;nbsp;going&amp;nbsp;on?&amp;nbsp;&amp;nbsp;Where&amp;nbsp;am&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;I&amp;nbsp;misunderstanding?&lt;/CODE&gt;&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 xxxx (
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
);
&lt;STRONG&gt;%put "SQL Return code and message" &amp;amp;sqlxrc &amp;amp;SQLXMSG;&lt;/STRONG&gt;
quit;
%mend;


data _null_/debug;
	set dbtblnames_complete;
	call execute('%tstuniqvalid(' || strip(newtblname1) || ');');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;so&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 02:30:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/716942#M221660</guid>
      <dc:creator>Gayle</dc:creator>
      <dc:date>2021-02-05T02:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: Data step question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/716958#M221666</link>
      <description>&lt;P&gt;I am unsure what the problem is, but:&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp;&lt;FONT face="courier new,courier"&gt;from connection to xxxx&amp;nbsp;&lt;/FONT&gt; &amp;nbsp; &amp;nbsp;should be&amp;nbsp; &lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;from connection to EIWP&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;2. you create the same data set&amp;nbsp; &lt;FONT face="courier new,courier"&gt;unique_validcustid&amp;nbsp; &lt;/FONT&gt;for each observation of&amp;nbsp;&amp;nbsp; &lt;FONT face="courier new,courier"&gt;dbtblnames_complete&amp;nbsp;&lt;/FONT&gt;so the data set will get overwritten&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 04:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/716958#M221666</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-02-05T04:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Data step question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/717083#M221735</link>
      <description>1. yes that is what it is in my code .the question/problem is : this code will do validation and in the data step there is a table of 2 table names being read want to capture the error code for each of the 2 tables. The first table does not have one of the column names and the second one the user does not have select access. However the "put" statement only gives me the error code/msg for the second table 2 times.&lt;BR /&gt;like so:&lt;BR /&gt;SQLXRC=3523&lt;BR /&gt;SQLXMSG=The user does not have SELECT access to WORK_05.ST_xxxx_chd_LOAD&lt;BR /&gt;SQLXRC=3523&lt;BR /&gt;SQLXMSG=The user does not have SELECT access to WORK_05.ST_xxxx_chd_LOAD&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 05 Feb 2021 14:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/717083#M221735</guid>
      <dc:creator>Gayle</dc:creator>
      <dc:date>2021-02-05T14:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Data step question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/717144#M221744</link>
      <description>&lt;P&gt;As you might have guessed, you are missing a key concept here.&amp;nbsp; CALL EXECUTE is not so intuitive when macro language is involved.&amp;nbsp; It runs code as soon as possible.&amp;nbsp; That means macro language statements execute immediately, but DATA and PROC step code have to wait until the DATA step is over.&amp;nbsp; As a result, the steps that take place (in order are):&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The DATA step begins to execute&lt;/LI&gt;
&lt;LI&gt;CALL EXECUTE runs your macro the first time.&amp;nbsp; It has to wait to run, PROC SQL, but ...&lt;/LI&gt;
&lt;LI&gt;CALL EXECUTE runs the %PUT statement immediately.&amp;nbsp; The DATA step has not finished, nor has PROC SQL run yet.&lt;/LI&gt;
&lt;LI&gt;CALL EXECUTE runs your macro the second time.&amp;nbsp; Again, it has to wait to run PROC SQL, but ...&lt;/LI&gt;
&lt;LI&gt;CALL EXECUTE runs the %PUT statement (for the second time) immediately.&lt;/LI&gt;
&lt;LI&gt;The DATA step ends.&lt;/LI&gt;
&lt;LI&gt;The PROC SQLs run.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The usual fix is to prevent CALL EXECUTE from running macro code immediately is to enclose it in the %NRSTR function.&amp;nbsp; You may need to check the syntax on this if this doesn't do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	call execute('%nrstr("%tstuniqvalid(" || strip(newtblname1) || ");"');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 17:34:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/717144#M221744</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-02-05T17:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: Data step question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/717156#M221748</link>
      <description>&lt;P&gt;Classic timing issue with CALL EXECUTE() and macros.&lt;/P&gt;
&lt;P&gt;Your macro has a mix of macro code and actual SAS code.&amp;nbsp; If you let SAS run the macro while it is pushing the call onto the stack to run after your data step then the macro statements run before the SAS code the macro generates has a chance to run.&lt;/P&gt;
&lt;P&gt;Do not use data step debugger with this. It is not adding any value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set dbtblnames_complete;
  call execute(cats('%nrstr(%tstuniqvalid)(' ,newtblname1, ');'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will notice the difference immediately in the SAS log.&amp;nbsp; Instead of seeing the SAS code the macro generates with the + in the LOG you will see just the macro call in the log.&lt;/P&gt;
&lt;PRE&gt;1252  %macro test(name);
1253  proc print data=&amp;amp;name (obs=1); run;
1254  %mend test;
1255
1256  data _null_;
1257    do name='sashelp.class';
1258      call execute(cats('%test(',name,')'));
1259    end;
1260  run;

NOTE: DATA statement used (Total process time):
      real time           0.13 seconds
      cpu time            0.01 seconds


NOTE: CALL EXECUTE generated line.
1    + proc print data=sashelp.class (obs=1); run;

NOTE: There were 1 observations read from the data set SASHELP.CLASS.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.09 seconds
      cpu time            0.01 seconds


1261
1262  data _null_;
1263    do name='sashelp.class';
1264      call execute(cats('%nrstr(%test)(',name,')'));
1265    end;
1266  run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


NOTE: CALL EXECUTE generated line.
1    + %test(sashelp.class)

NOTE: There were 1 observations read from the data set SASHELP.CLASS.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Feb 2021 17:48:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/717156#M221748</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-05T17:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Data step question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/717209#M221770</link>
      <description>&lt;P&gt;Hi all, related question for my own knowledge.&amp;nbsp; Is there a downside in using&amp;nbsp;&lt;STRONG&gt;DoSubl&lt;/STRONG&gt;() for the OP's code? My naive opinion is that it would fix the timing.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 20:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/717209#M221770</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-02-05T20:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Data step question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/717265#M221792</link>
      <description>It would.&lt;BR /&gt;Call dosubl() starts a new SAS session that runs in parallel and executes immediately.&lt;BR /&gt;The cost of doing this is high though. &lt;BR /&gt;</description>
      <pubDate>Sat, 06 Feb 2021 07:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/717265#M221792</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-02-06T07:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: Data step question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/717582#M221934</link>
      <description>thanks so much this worked (i.e call execute('%nrstr("%tstuniqvalid(" || strip(newtblname1) || ");"');, !!I will have to read more about this key concept to understand the flow</description>
      <pubDate>Mon, 08 Feb 2021 15:07:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/717582#M221934</guid>
      <dc:creator>Gayle</dc:creator>
      <dc:date>2021-02-08T15:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: Data step question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/717583#M221935</link>
      <description>Thanks so much for explaining further and I took out the debug</description>
      <pubDate>Mon, 08 Feb 2021 15:09:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-question/m-p/717583#M221935</guid>
      <dc:creator>Gayle</dc:creator>
      <dc:date>2021-02-08T15:09:14Z</dc:date>
    </item>
  </channel>
</rss>

