<?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 multiple datasets exists and do conditional statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-multiple-datasets-exists-and-do-conditional-statements/m-p/518179#M140204</link>
    <description>&lt;P&gt;&amp;nbsp;i have 3 datasets , fruits, vegetables and diary dataset&amp;nbsp; names. if datasets (&lt;SPAN&gt;fruits, vegetables,diary ) exists do condiftional statements&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if datasets (fruits, vegetables )&amp;nbsp;exists do conditional&amp;nbsp;statements&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;i have code as follows, but it running all the all conditions:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%macro checkds(dsn,dsn1,dsn2);&lt;BR /&gt;%if %sysfunc(exist(&amp;amp;dsn)) %then %do;&lt;BR /&gt;%if %sysfunc(exist(&amp;amp;dsn1)) %then %do;&lt;BR /&gt;%if %sysfunc(exist(&amp;amp;dsn2)) %then %do;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table test..&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;.....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;data _null_;&lt;BR /&gt;file print;&lt;BR /&gt;put #3 &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145066"&gt;@10&lt;/a&gt; "Data set &amp;amp;dsn. does not exist";&lt;BR /&gt;put #3 &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145066"&gt;@10&lt;/a&gt; "Data set &amp;amp;dsn1. does not exist";&lt;BR /&gt;put #3 &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145066"&gt;@10&lt;/a&gt; "Data set &amp;amp;dsn2. does not exist";&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend checkds;&lt;BR /&gt;%checkds(vegetables,Fruits,Dairy)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;---For two datasets check i have code as below----&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%macro checkds(dsn,dsn1);&lt;BR /&gt;%if %sysfunc(exist(&amp;amp;dsn)) %then %do;&lt;BR /&gt;%if %sysfunc(exist(&amp;amp;dsn1)) %then %do;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table test..&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;.....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;data _null_;&lt;BR /&gt;file print;&lt;BR /&gt;put #3 &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145066"&gt;@10&lt;/a&gt; "Data set &amp;amp;dsn. does not exist";&lt;BR /&gt;put #3 &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145066"&gt;@10&lt;/a&gt; "Data set &amp;amp;dsn1. does not exist";&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend checkds;&lt;BR /&gt;%checkds(vegetables,Fruits)&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;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 03 Dec 2018 18:40:29 GMT</pubDate>
    <dc:creator>radha009</dc:creator>
    <dc:date>2018-12-03T18:40:29Z</dc:date>
    <item>
      <title>Check multiple datasets exists and do conditional statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-multiple-datasets-exists-and-do-conditional-statements/m-p/518179#M140204</link>
      <description>&lt;P&gt;&amp;nbsp;i have 3 datasets , fruits, vegetables and diary dataset&amp;nbsp; names. if datasets (&lt;SPAN&gt;fruits, vegetables,diary ) exists do condiftional statements&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if datasets (fruits, vegetables )&amp;nbsp;exists do conditional&amp;nbsp;statements&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;i have code as follows, but it running all the all conditions:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%macro checkds(dsn,dsn1,dsn2);&lt;BR /&gt;%if %sysfunc(exist(&amp;amp;dsn)) %then %do;&lt;BR /&gt;%if %sysfunc(exist(&amp;amp;dsn1)) %then %do;&lt;BR /&gt;%if %sysfunc(exist(&amp;amp;dsn2)) %then %do;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table test..&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;.....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;data _null_;&lt;BR /&gt;file print;&lt;BR /&gt;put #3 &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145066"&gt;@10&lt;/a&gt; "Data set &amp;amp;dsn. does not exist";&lt;BR /&gt;put #3 &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145066"&gt;@10&lt;/a&gt; "Data set &amp;amp;dsn1. does not exist";&lt;BR /&gt;put #3 &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145066"&gt;@10&lt;/a&gt; "Data set &amp;amp;dsn2. does not exist";&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend checkds;&lt;BR /&gt;%checkds(vegetables,Fruits,Dairy)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;---For two datasets check i have code as below----&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%macro checkds(dsn,dsn1);&lt;BR /&gt;%if %sysfunc(exist(&amp;amp;dsn)) %then %do;&lt;BR /&gt;%if %sysfunc(exist(&amp;amp;dsn1)) %then %do;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table test..&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;.....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;data _null_;&lt;BR /&gt;file print;&lt;BR /&gt;put #3 &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145066"&gt;@10&lt;/a&gt; "Data set &amp;amp;dsn. does not exist";&lt;BR /&gt;put #3 &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145066"&gt;@10&lt;/a&gt; "Data set &amp;amp;dsn1. does not exist";&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend checkds;&lt;BR /&gt;%checkds(vegetables,Fruits)&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 18:40:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-multiple-datasets-exists-and-do-conditional-statements/m-p/518179#M140204</guid>
      <dc:creator>radha009</dc:creator>
      <dc:date>2018-12-03T18:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: Check multiple datasets exists and do conditional statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-multiple-datasets-exists-and-do-conditional-statements/m-p/518323#M140275</link>
      <description>&lt;P&gt;Try this....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Test;
proc sql noprint;
  create table MYWANTEDTABLES as
  select memname,
  case when memname='FRUITS' THEN 1
           when memname='VEGETABLES' THEN 3
		   when memname='DAIRY' THEN 5 END
  as table_tag,
  sum(case when memname='FRUITS' THEN 1
           when memname='VEGETABLES' THEN 3
		   when memname='DAIRY' THEN 5 END) AS TOTAL
   from sashelp.vtable
    where
    libname='SASHELP' and upcase(memname) in ('FRUITS','VEGETABLES','DAIRY') and memtype='DATA'
  order by calculated table_tag;
quit;

/* In the step above, i assigned a coded value whenever a table exist which when I sum-up will
give me an idea which table or tables exist. 

When the value of total is:
TOTAL =1 MEANS only FRUITS table exist.
TOTAL =4 MEANS FRUITS AND VEGETABLES tables exist.
TOTAL =9 MEANS FRUITS, VEGETABLES and DAIRY tables exist.
TOTAL =6 MEANS FRUITS and DAIRY tables exist.
TOTAL =8 MEANS VEGETABLES and DAIRY tables exist.

*/

%let mycount=&amp;amp;sqlobs.;
%put There are &amp;amp;mycount. tables found.;

%if %eval(&amp;amp;mycount.=3) %then %do;
  %put You can insert the appropriate steps here.;
%end;
/* When &amp;amp;MYCOUNT=
3: Means all 3 tables exist.
*/

proc sql noprint;
  select max(TOTAL) into: mytotal from MYWANTEDTABLES;
quit;

%let mytotal=&amp;amp;mytotal.;
%put &amp;amp;Mytotal.;

/* 
MYTOTAL =1 MEANS only FRUITS table exist.
MYTOTAL =4 MEANS FRUITS AND VEGETABLES tables exist.
MYTOTAL =9 MEANS FRUITS, VEGETABLES and DAIRY tables exist.
*/

/* Assuming you want to trigger additional steps when
fruits and vegetables only exist */
%if %eval(&amp;amp;mytotal.=4) %then %do;
  %put Insert additional codes when fruits and veges tables exist.;
%end;

%mend;

%Test;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Dec 2018 08:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-multiple-datasets-exists-and-do-conditional-statements/m-p/518323#M140275</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2018-12-04T08:10:49Z</dc:date>
    </item>
  </channel>
</rss>

