<?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: call execute error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/call-execute-error/m-p/245955#M45970</link>
    <description>&lt;P&gt;May be &amp;nbsp;I did not code correctly what I mean. &amp;nbsp;I want to &amp;nbsp;perform different operations based on the values of the Age in the sashelp.class. Let's say if age&amp;lt;15 create varialbe pre-teen="YES" and if age&amp;gt;15, pre-teen="NO" with the use of call execute.&lt;/P&gt;</description>
    <pubDate>Mon, 25 Jan 2016 19:12:32 GMT</pubDate>
    <dc:creator>SAS_inquisitive</dc:creator>
    <dc:date>2016-01-25T19:12:32Z</dc:date>
    <item>
      <title>call execute error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-execute-error/m-p/245947#M45964</link>
      <description>&lt;P&gt;This code gives the deired output data set but throws error in the log.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data _null_;
	set sashelp.class;

	if  _n_=1 then
		call execute("data test; set sashelp.class;");
	call execute("if AGE &amp;lt; 15 then output;");
	call execute("run;");
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Jan 2016 18:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-execute-error/m-p/245947#M45964</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-01-25T18:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: call execute error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-execute-error/m-p/245949#M45965</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	set sashelp.class;

	if  _n_=1 then do;
	call execute("data test; set sashelp.class;");
	call execute("if AGE &amp;lt; 15 then output;");
	call execute("run;");
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Jan 2016 18:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-execute-error/m-p/245949#M45965</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2016-01-25T18:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: call execute error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-execute-error/m-p/245950#M45966</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	set sashelp.class;

	if  _n_=1 then
	call execute("	data test; 
					set sashelp.class;
					if AGE &amp;lt; 15 then output; 
					run;");

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Looks like the entire data step must be in the same execute function.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2016 18:56:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-execute-error/m-p/245950#M45966</guid>
      <dc:creator>DanZ</dc:creator>
      <dc:date>2016-01-25T18:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: call execute error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-execute-error/m-p/245952#M45968</link>
      <description>&lt;P&gt;Perhaps easiest of all:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null_;&lt;BR /&gt;call execute("data test; set sashelp.class;");
call execute("if AGE &amp;lt; 15 then output;");
call execute("run;");
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no need to read SASHELP.CLASS.&amp;nbsp; You can use CALL EXECUTE without it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CALL EXECUTE is usually helpful when you need data from a SAS data set to construct the program.&amp;nbsp; Here, you don't so the program becomes much simpler.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2016 19:02:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-execute-error/m-p/245952#M45968</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-01-25T19:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: call execute error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-execute-error/m-p/245954#M45969</link>
      <description>&lt;P&gt;You have to think about it as a process:&lt;/P&gt;
&lt;PRE&gt;data _null_;
	set sashelp.class;&lt;/PRE&gt;
&lt;P&gt;These two lines are self explanatory, it sets each row in the dataset sashelp.class iteratively. &amp;nbsp;Then for each row returned from that dataset the condition is checked:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;	if  _n_=1 then
		call execute("data test; set sashelp.class;");&lt;/PRE&gt;
&lt;P&gt;As there is only one _n_ then this row gets called once and puts the code below into the compiler after the dataset finishes executing.&lt;/P&gt;
&lt;PRE&gt;data test; set sashelp.class;&lt;/PRE&gt;
&lt;P&gt;Which is probably what you want. &amp;nbsp;The next two statements are not part of the conditional:&lt;/P&gt;
&lt;PRE&gt;	call execute("if AGE &amp;lt; 15 then output;");
	call execute("run;");&lt;/PRE&gt;
&lt;P&gt;So these two rows execute for every row of dataset, so (assuming there is 3 rows in sashelp.class) the following code is sent to the compiler:&lt;/P&gt;
&lt;PRE&gt;if AGE &amp;lt; 15 then output; run;
if AGE &amp;lt; 15 then output; run;
if AGE &amp;lt; 15 then output; run;&lt;/PRE&gt;
&lt;P&gt;You will note that after the first run; the rest of the code becomes illegal.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is it your trying to do, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;&amp;nbsp;has stated there is no need to supply a dataset if you want code run once - as a datastep is a loop, each row being pulled in iteratively. &amp;nbsp;TBH though, from the code you have posted there doesn't appear to be any reason to do this in the first place. &amp;nbsp;Maybe if you post an example of what you are trying to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2016 19:11:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-execute-error/m-p/245954#M45969</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-25T19:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: call execute error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-execute-error/m-p/245955#M45970</link>
      <description>&lt;P&gt;May be &amp;nbsp;I did not code correctly what I mean. &amp;nbsp;I want to &amp;nbsp;perform different operations based on the values of the Age in the sashelp.class. Let's say if age&amp;lt;15 create varialbe pre-teen="YES" and if age&amp;gt;15, pre-teen="NO" with the use of call execute.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2016 19:12:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-execute-error/m-p/245955#M45970</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-01-25T19:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: call execute error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-execute-error/m-p/245965#M45971</link>
      <description>&lt;P&gt;Unfortunately, CALL EXECUTE doesn't do this.&amp;nbsp; A simple SAS program would, however:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;/P&gt;
&lt;P&gt;set sashelp.class;&lt;/P&gt;
&lt;P&gt;if age &amp;gt; 15 then preteen='YES';&lt;/P&gt;
&lt;P&gt;else preteen='NO';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CALL EXECUTE would only be useful if you wanted the program to change, depending on the contents of a SAS data set.&amp;nbsp; (In the case above, the program doesn't change at all.)&amp;nbsp; For example, suppose you wanted to code only one of these:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;/P&gt;
&lt;P&gt;set sashelp.class;&lt;/P&gt;
&lt;P&gt;preteen='YES';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;/P&gt;
&lt;P&gt;set sashelp.class;&lt;/P&gt;
&lt;P&gt;preteen='NO';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Further, suppose that you wanted SAS to generate one DATA step or the other depending on the largest value of AGE.&amp;nbsp; You could conceivably code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=sashelp.class;&lt;/P&gt;
&lt;P&gt;by age;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;set sashelp.class end=done;&lt;/P&gt;
&lt;P&gt;if _n_=1 then call execute('data test; set sashelp.class;');&lt;/P&gt;
&lt;P&gt;if done;&lt;/P&gt;
&lt;P&gt;if age &amp;gt; 15 then call execute("preteen='YES';");&lt;/P&gt;
&lt;P&gt;else call execute("preteen='NO';");&lt;/P&gt;
&lt;P&gt;call execute('run;');&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's just a simple to example to illustrate ... the DATA step that SAS sees will change, depending on the largest value of AGE.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2016 19:40:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-execute-error/m-p/245965#M45971</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-01-25T19:40:51Z</dc:date>
    </item>
  </channel>
</rss>

