<?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 check for the existence a particular variable based on its value, if the dataset exists? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-for-the-existence-a-particular-variable-based-on/m-p/375847#M276549</link>
    <description>&lt;P&gt;Thank you for the reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I am looking for something like&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%if %sysfunc(exist(City_US_aand_Canada where country='US'))%then%do&lt;/PRE&gt;&lt;P&gt;But it does not seem to work&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea on how to look into this?&lt;/P&gt;</description>
    <pubDate>Thu, 13 Jul 2017 21:45:27 GMT</pubDate>
    <dc:creator>jjames1</dc:creator>
    <dc:date>2017-07-13T21:45:27Z</dc:date>
    <item>
      <title>How to check for the existence a particular variable based on its value, if the dataset exists?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-for-the-existence-a-particular-variable-based-on/m-p/375820#M276544</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to write a condition in order to check the existence&amp;nbsp;a particular variable based on its value if the dataset exist or else come out &amp;nbsp;of the loop and do something else.&lt;/P&gt;&lt;P&gt;To get a clear picture . Consider the following table&amp;nbsp;&lt;STRONG&gt;City_US_and_Canada&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;City&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt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&gt;&lt;P&gt;Edmonton&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;AB&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now in my case first of all I need to check if the table&amp;nbsp;&lt;STRONG&gt;City_US_and_Canada&amp;nbsp;&lt;/STRONG&gt;exist. For that I use the following piece of code&lt;/P&gt;&lt;P&gt;%if %sysfunc(exist(City_US_aand_Canada))%then%do&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now if this table exists I need to filter it just for one country say US. My final output should look like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;City&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;State&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;US&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Albany&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;NY&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;US&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Baker&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;OR&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;US&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Austin&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;TX&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me to fix this one&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 19:55:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-for-the-existence-a-particular-variable-based-on/m-p/375820#M276544</guid>
      <dc:creator>jjames1</dc:creator>
      <dc:date>2017-07-13T19:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to check for the existence a particular variable based on its value, if the dataset exists?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-for-the-existence-a-particular-variable-based-on/m-p/375826#M276545</link>
      <description>&lt;P&gt;You need to give more context to get a complete answer.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set City_US_and_Canada;
 where Country="US";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 20:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-for-the-existence-a-particular-variable-based-on/m-p/375826#M276545</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-13T20:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to check for the existence a particular variable based on its value, if the dataset exists?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-for-the-existence-a-particular-variable-based-on/m-p/375827#M276546</link>
      <description>&lt;P&gt;You apparently want to conditionally execute a DATA step where the step reads the discovered data set and outputs a subset of observations, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro t;
  %if %sysfunc(exist(City_US_and_Canada)) %then %do;
    data want;
      set City_US_and_Canada;
      where country='US';
    run;
  %end;&lt;BR /&gt;  %else %put City_US_and_Canada dataset not fuond ;
%mend;
options mprint;
%t;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Jul 2017 20:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-for-the-existence-a-particular-variable-based-on/m-p/375827#M276546</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-07-13T20:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to check for the existence a particular variable based on its value, if the dataset exists?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-for-the-existence-a-particular-variable-based-on/m-p/375830#M276547</link>
      <description>&lt;P&gt;Thank you for the reply!&lt;/P&gt;&lt;P&gt;I am generating this tables directly from XML files in SAS. In my case I have different XML files. So when I read the xml files ,I need to check if the table is present to do the transformations. Once if the table is present I need to check for the variables based on its values.&lt;/P&gt;&lt;P&gt;This is&amp;nbsp;something that I was looking to do&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%if %sysfunc(exist(City_US_aand_Canada where country='US'))%then%do&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;But this one is not working&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 21:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-for-the-existence-a-particular-variable-based-on/m-p/375830#M276547</guid>
      <dc:creator>jjames1</dc:creator>
      <dc:date>2017-07-13T21:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to check for the existence a particular variable based on its value, if the dataset exists?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-for-the-existence-a-particular-variable-based-on/m-p/375847#M276549</link>
      <description>&lt;P&gt;Thank you for the reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I am looking for something like&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%if %sysfunc(exist(City_US_aand_Canada where country='US'))%then%do&lt;/PRE&gt;&lt;P&gt;But it does not seem to work&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea on how to look into this?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 21:45:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-for-the-existence-a-particular-variable-based-on/m-p/375847#M276549</guid>
      <dc:creator>jjames1</dc:creator>
      <dc:date>2017-07-13T21:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to check for the existence a particular variable based on its value, if the dataset exists?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-for-the-existence-a-particular-variable-based-on/m-p/375861#M276550</link>
      <description>&lt;P&gt;What you are attempting is not going to be a one line of code operation though after you get something working &lt;FONT color="#ff0000" size="4"&gt;&lt;STRONG&gt;without macro code &lt;/STRONG&gt;&lt;FONT color="#000000" size="2"&gt;then something can be done. &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" size="4"&gt;&lt;FONT color="#000000" size="2"&gt;Steps would be &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" size="4"&gt;&lt;FONT color="#000000" size="2"&gt;1) verify the existence of the dataset&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" size="4"&gt;&lt;FONT color="#000000" size="2"&gt;2) verify the existence of the variable in that data set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" size="4"&gt;&lt;FONT color="#000000" size="2"&gt;if both of those conditions are met then you can start looking for specific values.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" size="4"&gt;&lt;FONT color="#000000" size="2"&gt;For instance:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#ff0000" size="4"&gt;&lt;FONT color="#000000" size="2"&gt;proc sql noprint;
   select *
   from dictionary.columns
   where Libname='SASHELP' and Memname=('CLASS')
   and upcase(name)='SEX'
   ;
quit;

%put &amp;amp;sqlobs;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT color="#ff0000" size="4"&gt;&lt;FONT color="#000000" size="2"&gt;The select examines you SAS metadata which has libraries (LIBNAME), data sets (MEMNAME) and variables (NAME) plus characteristics of the variables. The macro variable SQLOBS is an automatic variable that contains the number of records returned by the latest Proc SQL query. &lt;FONT size="2"&gt;&amp;amp;sqlobs will be 0 if no records were returned.&lt;/FONT&gt;&amp;nbsp;Note that the Libname and Memname are stored as upper case in the dictionary table, variablenames may be mixed case so be careful on syntax using those.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" size="4"&gt;&lt;FONT color="#000000" size="2"&gt;So you could run that SQL snippet and and then use&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" size="4"&gt;&lt;FONT color="#000000" size="2"&gt;%if &amp;amp;sqlobs &amp;gt; 0 %then %do.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" size="4"&gt;&lt;FONT color="#000000" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" size="4"&gt;&lt;FONT color="#000000" size="2"&gt;If I were doing this frequently might create function or small macro to return the value of sqlobs when passed a library (which could default to WORK) , a data set name and a variable name as parameters. I'll leave that as a small exercise for the intersted reader at this time.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 22:49:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-for-the-existence-a-particular-variable-based-on/m-p/375861#M276550</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-07-13T22:49:56Z</dc:date>
    </item>
  </channel>
</rss>

