<?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: how to use a proc delete inside of a if statement in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/911667#M44178</link>
    <description>&lt;P&gt;Note that it will work with an IF statement since SAS will convert types automatically.&amp;nbsp; But it&amp;nbsp; will not work in macro %IF code since the macro processor just compares strings.&lt;/P&gt;
&lt;PRE&gt;1    data _null_;
2      if 1 = '1' then put 'equal';
3      else put 'not equal';
4    run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      2:10
equal
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


5
6    %if 1 = '1' %then %do; %put equal; %end;
7    %else %do; %put not equal; %end;
not equal
&lt;/PRE&gt;</description>
    <pubDate>Tue, 16 Jan 2024 16:35:21 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-01-16T16:35:21Z</dc:date>
    <item>
      <title>how to use a proc delete inside of a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/911661#M44175</link>
      <description>&lt;P&gt;How to use a proc delete in a if statement.&lt;/P&gt;
&lt;P&gt;In our case, if Flag eq '0' then delete class_org;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let flag=0;
data class class_org;
set sashelp.class;
	if &amp;amp;flag eq '1' then
	do;
		output class_org;
		if age eq 15 then age=25;
		output class;
	end;
	else;
	do;
		proc delete lib=work data=class_org;
		run;
		output class;
	end; 
	
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jan 2024 16:01:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/911661#M44175</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-01-16T16:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a proc delete inside of a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/911664#M44176</link>
      <description>&lt;P&gt;PROCs cannot be run "inside" a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have the macro variable &amp;amp;FLAG, you could easily turn this into a macro %IF statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let flag=0;
%if &amp;amp;flag=1 %then %do;
data class class_org;
    set sashelp.class;
    output class_org;
    if age eq 15 then age=25;
    output class;
run;
%end;
%else %do;
proc delete lib=work data=class_org;
run;
quit;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please remember that to branch on macro variable values, you need a macro %IF and not a DATA step IF.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, please understand that in your original code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;amp;flag eq '1'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;seems doomed to fail. If &amp;amp;FLAG=0, it is not equal to '1' and if &amp;amp;FLAG=1, it is not equal to '1'. See if you can understand why I said these are not equal.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 17:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/911664#M44176</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-01-16T17:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a proc delete inside of a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/911665#M44177</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You cannot invoke a procedure in the middle of data step, so you can try checking the value before executing any Base SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, you can try something like the following untested code. Also note that as the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;amp;flag&lt;/FONT&gt;&amp;nbsp;value has no quotes saved with it when you initialise it, you do not need the quotes around the 1 when testing for equality.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;flag = 1 %then
%do;
  /* data step code here */
%end;
%else
%do;
  /* proc delete code here */
%end;&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Changed 0 to 1 in explanation.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 16:42:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/911665#M44177</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2024-01-16T16:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a proc delete inside of a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/911667#M44178</link>
      <description>&lt;P&gt;Note that it will work with an IF statement since SAS will convert types automatically.&amp;nbsp; But it&amp;nbsp; will not work in macro %IF code since the macro processor just compares strings.&lt;/P&gt;
&lt;PRE&gt;1    data _null_;
2      if 1 = '1' then put 'equal';
3      else put 'not equal';
4    run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      2:10
equal
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


5
6    %if 1 = '1' %then %do; %put equal; %end;
7    %else %do; %put not equal; %end;
not equal
&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jan 2024 16:35:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/911667#M44178</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-01-16T16:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a proc delete inside of a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/912496#M44193</link>
      <description>&lt;P&gt;Here's my final code. Thank for your help.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _null_;
%global CorrectionFlag;
%let CorrectionFlag = 0;
set TEMP.PREMHF;
if (cie eq '8' and broker_group_ind eq 'HW' and branch eq '89') Then 
do;
	%let CorrectionFlag = 1;
end;
RUN;
/*%let CorrectionFlag=0;*/
%put &amp;amp;=CorrectionFlag;

Data temp.premhf temp.premhf_org;
set temp.premhf;
if &amp;amp;CorrectionFlag eq 1 then
do;
	output temp.premhf_org;
	if (cie eq '8' and broker_group_ind eq 'HW' and branch = '89') then 
	do;
		branch = '86';		
	end;
	output temp.premhf;
end;
else 
do;	
	output temp.premhf;
end;
run;
%put &amp;amp;=CorrectionFlag;
%if &amp;amp;CorrectionFlag eq 0 %then
%do;
	proc delete library=temp data=premhf_org;
	run;
%end;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Jan 2024 16:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/912496#M44193</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-01-22T16:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a proc delete inside of a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/912501#M44194</link>
      <description>&lt;P&gt;That first step WILL NOT WORK.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MACRO code executes BEFORE the data step even gets compiled.&amp;nbsp; Definitely before it can run. So you ran this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global CorrectionFlag;
%let CorrectionFlag = 0;
%let CorrectionFlag = 1;
data _null_;
  set TEMP.PREMHF;
  if (cie eq '8' and broker_group_ind eq 'HW' and branch eq '89') then do;end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So the macro variable&amp;nbsp;CorrectionFlag&amp;nbsp;is always going to be set to 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the data step logic to change the value of the macro variable you need to use CALL SYMPUTX().&amp;nbsp; And there is no need to set it more than once.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global CorrectionFlag;
%let CorrectionFlag = 0;
data _null_;
  set TEMP.PREMHF;
  if (cie eq '8' and broker_group_ind eq 'HW' and branch eq '89') then do;
    call symputx('CorrectionFlag','1');
    stop;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But since you are going to use it to generate the DELETE step after the main step you don't need that extra data step at all.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let &amp;amp;CorrectionFlag=0;

data temp.premhf temp.premhf_org;
  set temp.premhf;
  output;
  if (cie eq '8' and broker_group_ind eq 'HW' and branch = '89') then do;
    call symputx('CorrectionFlag','1');
    output temp.premhf_org;
    branch = '86';  
    output temp.premhf;
  end;
  else do; 
    output temp.premhf;
  end;
run;

%if &amp;amp;CorrectionFlag eq 0 %then %do;
proc delete library=temp data=premhf_org;
run;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you do know in advance whether or not you need the second dataset you can use macro logic to skip making it in the first place.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;CorrectionFlag eq 1 %then %do;
data temp.premhf temp.premhf_org;
  set temp.premhf;
  output;
  if (cie eq '8' and broker_group_ind eq 'HW' and branch = '89') then do;
    output temp.premhf_org;
    branch = '86';  
    output temp.premhf;
  end;
  else do; 
    output temp.premhf;
  end;
run;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But why not just do what you want directly?&amp;nbsp; It is pretty simple using PROC SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table temp.premhf_org as
  select * from temp.premhf
  where (cie eq '8' and broker_group_ind eq 'HW' and branch = '89') 
;
%if &amp;amp;sqlobs %then %do;
update temp.premhf
  set branch='86' 
  where (cie eq '8' and broker_group_ind eq 'HW' and branch = '89') 
;
%end;
%else %do;
drop table temp.premhf_org;
%end;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2024 16:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/912501#M44194</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-01-22T16:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a proc delete inside of a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/912502#M44195</link>
      <description>&lt;P&gt;Does this work? I can't see how it would possibly work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't have your data set, but try these variations of your code on SASHELP.CLASS. The first one, where name='Janet', should return a 1 because her weight is &amp;gt;60 and her sex is 'F'. The second one, where name='Alfred', should return a zero because Alfred is not 'F', but it returns a 1. The third one, where the person's name is not in the data set, also returns a 1. No matter what is in the data set, correctionflag will be 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Program 1 */
Data _null_;
%let CorrectionFlag = 0;
set sashelp.class(where=(name='Janet'));
if weight &amp;gt; 60 and sex='F' Then 
do;
	%let CorrectionFlag = 1;
end;
RUN;

%put &amp;amp;=correctionFlag;

/* Program 2 */
Data _null_;
%let CorrectionFlag = 0;
set sashelp.class(where=(name='Alfred'));
if weight &amp;gt; 60 and sex='F' Then 
do;
	%let CorrectionFlag = 1;
end;
RUN;

%put &amp;amp;=correctionFlag;

/* Program 3 */
Data _null_;
%let CorrectionFlag = 0;
set sashelp.class(where=(name='Warren'));
if weight &amp;gt; 60 and sex='F' Then 
do;
	%let CorrectionFlag = 1;
end;
RUN;

%put &amp;amp;=correctionFlag;&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;Earlier I showed working code to allow you to run a PROC DELETE if certain conditions are true. You have changed that code in significant ways, and it won't work now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%LET does not work inside a data step the way you think it does. If you need to get data step variable values into a macro variable, you could use &lt;A href="https://documentation.sas.com/doc/en/vdmmlcdc/8.1/mcrolref/p1fa0ay5pzr9yun1mvqxv8ipzd4d.htm" target="_self"&gt;CALL SYMPUTX()&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2024 17:29:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/912502#M44195</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-01-22T17:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a proc delete inside of a if statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/912603#M44196</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The fact that macro code is executed separately (before) data step code can be seen in the following data step which ends with &lt;FONT face="courier new,courier"&gt;run cancel;&lt;/FONT&gt; to prevent the data step from being executed, but the macro code &lt;EM&gt;&lt;STRONG&gt;is&lt;/STRONG&gt; &lt;/EM&gt;executed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Amir_0-1705996422978.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92886i63D48B811D6C34F4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Amir_0-1705996422978.png" alt="Amir_0-1705996422978.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2024 08:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-proc-delete-inside-of-a-if-statement/m-p/912603#M44196</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2024-01-23T08:03:06Z</dc:date>
    </item>
  </channel>
</rss>

