<?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 check for and delete var in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/check-for-and-delete-var/m-p/401796#M66798</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following code that generates an error. I am checking the matrix 'have' for the variable 'cusum'. If 'cusum' exists it is removed. The error I get is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 117-185: There was 1 unclosed DO block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	data _null_;
		dsid=open('have');
		check=varnum(dsid,'cusum');

		if check=1 then
			do;
	data have(drop=cusum);
	set have;
	run;
			end;
		run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 06 Oct 2017 14:39:10 GMT</pubDate>
    <dc:creator>capam</dc:creator>
    <dc:date>2017-10-06T14:39:10Z</dc:date>
    <item>
      <title>check for and delete var</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/check-for-and-delete-var/m-p/401796#M66798</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following code that generates an error. I am checking the matrix 'have' for the variable 'cusum'. If 'cusum' exists it is removed. The error I get is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 117-185: There was 1 unclosed DO block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	data _null_;
		dsid=open('have');
		check=varnum(dsid,'cusum');

		if check=1 then
			do;
	data have(drop=cusum);
	set have;
	run;
			end;
		run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Oct 2017 14:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/check-for-and-delete-var/m-p/401796#M66798</guid>
      <dc:creator>capam</dc:creator>
      <dc:date>2017-10-06T14:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: check for and delete var</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/check-for-and-delete-var/m-p/401801#M66799</link>
      <description>&lt;P&gt;You can't have a data step inside a data step. That is the cause of the ERROR message you are seeing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A better way to check to see if a variable exists and then delete it would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use PROC SQL to query the DICTIONARY.COLUMNS table to see if the variable exists; and if it exists, then use PROC DATASETS to remove the variable from the data set. This would have to be done in a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm curious as to why you need to conditionally delete a variable if it exists, as normally leaving an unwanted variable in a data set causes no problems other than taking up slightly more disk space.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 14:51:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/check-for-and-delete-var/m-p/401801#M66799</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-10-06T14:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: check for and delete var</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/check-for-and-delete-var/m-p/401824#M66801</link>
      <description>&lt;P&gt;Something like the below - although I totally agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;, there is rarely a need to delete a variable if you don't know about it up front, sounds like a lack of knowledge about your data.&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.vcolumn (where=(libname="WORK" and memname="HAVE" and name="CUSUM"));
  call execute('data work.have; set work.have (drop=cusum); run;');
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Oct 2017 15:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/check-for-and-delete-var/m-p/401824#M66801</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-06T15:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: check for and delete var</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/check-for-and-delete-var/m-p/401831#M66802</link>
      <description>&lt;P&gt;You don't actually need to check for the existence of the variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The system option DKRICOND determines whether or not and error is generated when you drop/keep/rename a variable that doesn't exist.&amp;nbsp; It's default is DKRICOND=ERROR, but you can set it to NOWARN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
  x=1;
run;
data have2;
  x=2;
  cusum=1;
run;

options dkricond=error;
data want;
  set have1(drop=cusum)  /*causes error cuz cusum does not exist*/
      have2(drop=cusum)
  ;
  put _all_;
run;


options dkricond=nowarn;
data want;
  set have1(drop=cusum)  /*no error cuz DKRICOND=NOWARN*/
      have2(drop=cusum)
  ;
  put _all_;
run;
options dkricond=error;  *restore the default;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Oct 2017 16:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/check-for-and-delete-var/m-p/401831#M66802</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-10-06T16:11:42Z</dc:date>
    </item>
  </channel>
</rss>

