<?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 tell whether dataset contains a specific column?! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-tell-whether-dataset-contains-a-specific-column/m-p/801598#M315480</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let go_on=no;

proc sql noprint;
select "yes" into :go_on
from dictionary.columns
where libname = "LIBRARY" and memname = "DATASET" and upcase(name) = "VARIABLE";
quit;

%if &amp;amp;go_on. = yes
%then %do;
/* code */
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the SQL does not find a matching entry, the macro variable is left untouched.&lt;/P&gt;</description>
    <pubDate>Fri, 11 Mar 2022 06:03:00 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-03-11T06:03:00Z</dc:date>
    <item>
      <title>How to tell whether dataset contains a specific column?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-tell-whether-dataset-contains-a-specific-column/m-p/801579#M315463</link>
      <description>How to tell whether dataset contains a specific column?!  Any way to do it by fetching meta info?! rather than 
go proc contents?! 

Need a macro to tell whether dataset contains a specific column or not. If yes, delete column. If not, do nothing.</description>
      <pubDate>Fri, 11 Mar 2022 02:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-tell-whether-dataset-contains-a-specific-column/m-p/801579#M315463</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-03-11T02:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to tell whether dataset contains a specific column?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-tell-whether-dataset-contains-a-specific-column/m-p/801581#M315465</link>
      <description>Yes, this can be done by accessing dictionary tables with proc sql.</description>
      <pubDate>Fri, 11 Mar 2022 03:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-tell-whether-dataset-contains-a-specific-column/m-p/801581#M315465</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-03-11T03:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to tell whether dataset contains a specific column?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-tell-whether-dataset-contains-a-specific-column/m-p/801595#M315477</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409584"&gt;@hellohere&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;How to tell whether dataset contains a specific column?! Any way to do it by fetching meta info?! rather than go proc contents?! Need a macro to tell whether dataset contains a specific column or not. If yes, delete column. If not, do nothing.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you are going to delete it if it exits?&lt;/P&gt;
&lt;P&gt;Sounds like you just need to check out the DKRICOND or DKROCOND option.&lt;/P&gt;
&lt;P&gt;You can use that option to suppress any error (or even any warning) if you try to drop a variable that does not exist.&lt;/P&gt;
&lt;P&gt;Consider this program:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set sashelp.class(drop=X);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;770   %let dkricond=%sysfunc(getoption(dkricond));
771   %put &amp;amp;=dkricond;
DKRICOND=ERROR
772   data want;
773     set sashelp.class(drop=X);
ERROR: The variable X in the DROP, KEEP, or RENAME list has never been referenced.
774   run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.WANT may be incomplete.  When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set WORK.WANT was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.04 seconds


775   options dkricond=nowarn;
776   data want;
777     set sashelp.class(drop=X);
778   run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.WANT has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.00 seconds

779   options dkricond=&amp;amp;dkricond;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Mar 2022 05:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-tell-whether-dataset-contains-a-specific-column/m-p/801595#M315477</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-11T05:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to tell whether dataset contains a specific column?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-tell-whether-dataset-contains-a-specific-column/m-p/801598#M315480</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let go_on=no;

proc sql noprint;
select "yes" into :go_on
from dictionary.columns
where libname = "LIBRARY" and memname = "DATASET" and upcase(name) = "VARIABLE";
quit;

%if &amp;amp;go_on. = yes
%then %do;
/* code */
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the SQL does not find a matching entry, the macro variable is left untouched.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 06:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-tell-whether-dataset-contains-a-specific-column/m-p/801598#M315480</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-11T06:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to tell whether dataset contains a specific column?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-tell-whether-dataset-contains-a-specific-column/m-p/801631#M315499</link>
      <description>&lt;P&gt;Is this the macro (function) you are looking for?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://core.sasjs.io/mf__existvar_8sas.html" target="_blank"&gt;https://core.sasjs.io/mf__existvar_8sas.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 10:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-tell-whether-dataset-contains-a-specific-column/m-p/801631#M315499</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2022-03-11T10:52:52Z</dc:date>
    </item>
  </channel>
</rss>

