<?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: Drop a variable if exits in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Drop-a-variable-if-exits/m-p/388177#M11721</link>
    <description>&lt;P&gt;Hey SASPhile,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Two methods spring to mind ... one is to interogate the sashelp.vcolumn dataset to see if the variable exists there then conditionally write the variable into your datastep using a macro.&amp;nbsp; Second (and I'm not sure how others will feel about this option) is to use&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;option&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;DKRICOND&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=NOWARN; &lt;/FONT&gt;before the datastep with &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;option&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;DKRICOND&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=ERROR;&amp;nbsp;&lt;FONT face="arial,helvetica,sans-serif"&gt;after the datastep&amp;nbsp;.&amp;nbsp; Setting DKRICOND to nowarn before your datastep will suppress the error message that would normally be generated by trying to drop a variable that does not exist and will let your datastep execute.&amp;nbsp; As I say, this probably isn't best practice, but dependent on your data may be a simpler solution.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Good luck!&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Aug 2017 15:45:59 GMT</pubDate>
    <dc:creator>BenbowL</dc:creator>
    <dc:date>2017-08-15T15:45:59Z</dc:date>
    <item>
      <title>Drop a variable if exits</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Drop-a-variable-if-exits/m-p/388169#M11719</link>
      <description>&lt;P&gt;How to drop a variable if it exists?There are hynds of&amp;nbsp; datasets and not all datasets have that variable.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 14:41:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Drop-a-variable-if-exits/m-p/388169#M11719</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2017-08-15T14:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: Drop a variable if exits</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Drop-a-variable-if-exits/m-p/388177#M11721</link>
      <description>&lt;P&gt;Hey SASPhile,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Two methods spring to mind ... one is to interogate the sashelp.vcolumn dataset to see if the variable exists there then conditionally write the variable into your datastep using a macro.&amp;nbsp; Second (and I'm not sure how others will feel about this option) is to use&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;option&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;DKRICOND&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=NOWARN; &lt;/FONT&gt;before the datastep with &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;option&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;DKRICOND&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=ERROR;&amp;nbsp;&lt;FONT face="arial,helvetica,sans-serif"&gt;after the datastep&amp;nbsp;.&amp;nbsp; Setting DKRICOND to nowarn before your datastep will suppress the error message that would normally be generated by trying to drop a variable that does not exist and will let your datastep execute.&amp;nbsp; As I say, this probably isn't best practice, but dependent on your data may be a simpler solution.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Good luck!&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 15:45:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Drop-a-variable-if-exits/m-p/388177#M11721</guid>
      <dc:creator>BenbowL</dc:creator>
      <dc:date>2017-08-15T15:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: Drop a variable if exits</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Drop-a-variable-if-exits/m-p/388244#M11730</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16600"&gt;@SASPhile&lt;/a&gt;&amp;nbsp;You might find this useful, call this macro to your convenience:&lt;/P&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;&lt;STRONG&gt;%macro&lt;/STRONG&gt; VarExist(ds, var);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %local rc dsid;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let dsid = %sysfunc(open(&amp;amp;ds));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if %sysfunc(varnum(&amp;amp;dsid, &amp;amp;var)) &amp;gt; &lt;STRONG&gt;0&lt;/STRONG&gt; %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let result = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put NOTE: Var &amp;amp;var exists in &amp;amp;ds;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop &amp;amp;var;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let result = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put NOTE: Var &amp;amp;var not exists in &amp;amp;ds;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let rc = %sysfunc(close(&amp;amp;dsid));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt; VarExist;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;%&lt;STRONG&gt;&lt;EM&gt;VarExist&lt;/EM&gt;&lt;/STRONG&gt;(sashelp.class, name);&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 18:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Drop-a-variable-if-exits/m-p/388244#M11730</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-08-15T18:23:26Z</dc:date>
    </item>
  </channel>
</rss>

