<?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: Iterating Specific Rows in CALL EXECUTE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Specific-Rows-in-CALL-EXECUTE/m-p/724356#M224889</link>
    <description>&lt;P&gt;"iterate" is not the right word here.&lt;/P&gt;
&lt;P&gt;The word you are looking for is CONDITIONAL.&amp;nbsp; As in how can I conditionally generate code using call execute.&amp;nbsp; In this specific case you need to generate special code before the first observation.&amp;nbsp; You could also generate code after the last observation, but that is is not really required as you could always just type that code directly into the program after the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your final data step is NOT the same as the previous example as it is skipping the SET WANT statement.&amp;nbsp; &amp;nbsp;But since you made want as a dataset with one observation and no variables there will not be any difference.&amp;nbsp; However is there was some other dataset WANT that you want to modify then the SET statement would make a difference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To test if you are on the first iteration of the data step use the _N_ automatic variable.&amp;nbsp; To test if you are on the last use the END= option on the SET statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set have end=eof;
  if _n_=1 then call execute('data want; set want;');
  call execute(cats(name,'=1;'));
  if eof then call execute('run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 08 Mar 2021 04:50:20 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-03-08T04:50:20Z</dc:date>
    <item>
      <title>Iterating Specific Rows in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Specific-Rows-in-CALL-EXECUTE/m-p/724353#M224888</link>
      <description>&lt;P&gt;The following uses a data set HAVE to create three variables JACK JAMES JOHN in a data set WANT.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input name $;
cards;
Jack
James
John
;

data want;
run;

data _null_;
	set have;
	call execute("data want;set want;"||name||"=1;run;");
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So, this is equivalent to&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
run;

data want;
	set want;
	Jack=1;
run;

data want;
	set want;
	James=1;
run;

data want;
	set want;
	John=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But, can I iterate one specific row via CALL EXECUTE using the data as follows?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	Jack=1;
	James=1;
	John=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Mar 2021 04:40:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Specific-Rows-in-CALL-EXECUTE/m-p/724353#M224888</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2021-03-08T04:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Specific Rows in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Specific-Rows-in-CALL-EXECUTE/m-p/724356#M224889</link>
      <description>&lt;P&gt;"iterate" is not the right word here.&lt;/P&gt;
&lt;P&gt;The word you are looking for is CONDITIONAL.&amp;nbsp; As in how can I conditionally generate code using call execute.&amp;nbsp; In this specific case you need to generate special code before the first observation.&amp;nbsp; You could also generate code after the last observation, but that is is not really required as you could always just type that code directly into the program after the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your final data step is NOT the same as the previous example as it is skipping the SET WANT statement.&amp;nbsp; &amp;nbsp;But since you made want as a dataset with one observation and no variables there will not be any difference.&amp;nbsp; However is there was some other dataset WANT that you want to modify then the SET statement would make a difference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To test if you are on the first iteration of the data step use the _N_ automatic variable.&amp;nbsp; To test if you are on the last use the END= option on the SET statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set have end=eof;
  if _n_=1 then call execute('data want; set want;');
  call execute(cats(name,'=1;'));
  if eof then call execute('run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Mar 2021 04:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Specific-Rows-in-CALL-EXECUTE/m-p/724356#M224889</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-08T04:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Specific Rows in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Specific-Rows-in-CALL-EXECUTE/m-p/724372#M224895</link>
      <description>&lt;P&gt;A variation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set HAVE nobs=NOBS;
  if _N_=1 then call execute('data WANT; set WANT;');
  call execute(cats(NAME,'=1;'));
  if _N_=NOBS then call execute('run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Mar 2021 06:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Specific-Rows-in-CALL-EXECUTE/m-p/724372#M224895</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-08T06:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Specific Rows in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Specific-Rows-in-CALL-EXECUTE/m-p/724464#M224929</link>
      <description>&lt;P&gt;one more variation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input name $;
cards;
Jack
James
John
;
run;

data want;
run;

data _null_;
  call execute('data want; set want;');
  do until(eof);
    set have end=eof;
    call execute(cats(name,'=1;'));
  end;
  call execute('run;');
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 11:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Specific-Rows-in-CALL-EXECUTE/m-p/724464#M224929</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-03-08T11:29:31Z</dc:date>
    </item>
  </channel>
</rss>

