<?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: Check a dataset exist or not in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-a-dataset-exist-or-not/m-p/396361#M95685</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139803"&gt;@R_Chung&lt;/a&gt; wrote:&lt;BR /&gt;Is there a missing in hyperlink &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, I assumed that google is sufficient.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use terms "SAS macro check if data exists"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Returns:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/670.html" target="_blank"&gt;http://support.sas.com/kb/24/670.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Sep 2017 14:43:09 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-09-15T14:43:09Z</dc:date>
    <item>
      <title>Check a dataset exist or not</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-a-dataset-exist-or-not/m-p/396140#M95604</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to check whether a dataset exist first then join the dataset with another dataset.&lt;/P&gt;&lt;P&gt;Below is my code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (exist(ot_reclus_kw_kc)) then do;
    data semi_ot_result; 
	 	set ot_reclus_kw_kc semi_ot_result; 
	 run;
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there any errors/mistakes?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 03:50:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-a-dataset-exist-or-not/m-p/396140#M95604</guid>
      <dc:creator>R_Chung</dc:creator>
      <dc:date>2017-09-15T03:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Check a dataset exist or not</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-a-dataset-exist-or-not/m-p/396154#M95608</link>
      <description>&lt;P&gt;You can't execute conditional code like that in SAS.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'll have to use macro programming and %if/%then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you search on here or lexjansen.com you'll find a lot of examples on how to do this.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 04:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-a-dataset-exist-or-not/m-p/396154#M95608</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-15T04:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: Check a dataset exist or not</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-a-dataset-exist-or-not/m-p/396164#M95611</link>
      <description>&lt;P&gt;Until you are very familiar with the possible errors in SAS, I suggest that you do NOT combine data sets or use the structure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data someset;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set someset ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;as if there is an error you may corrupt or modify you dataset someset in such a way that you lose or destroy some existing data and have to recover the original version from somewhere else. I would recomend testing with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data combined;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set ot_reclus_kw_kt semi_ot_result;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may find that you want a merge or update instead of set and if you make the wrong choice ...&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 05:20:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-a-dataset-exist-or-not/m-p/396164#M95611</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-15T05:20:26Z</dc:date>
    </item>
    <item>
      <title>Re: Check a dataset exist or not</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-a-dataset-exist-or-not/m-p/396168#M95613</link>
      <description>Is there a missing in hyperlink &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;</description>
      <pubDate>Fri, 15 Sep 2017 06:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-a-dataset-exist-or-not/m-p/396168#M95613</guid>
      <dc:creator>R_Chung</dc:creator>
      <dc:date>2017-09-15T06:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: Check a dataset exist or not</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-a-dataset-exist-or-not/m-p/396176#M95615</link>
      <description>&lt;P&gt;Try this......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Submit your code, check the sas log. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check your DATA and SET statements. &amp;nbsp;Changing the position of the tables in your SET statement will create the difference unless the tables have identical structure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the structure is identical then better use proc append or proc sql.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Creating a macro program like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO &amp;lt;MACRONAME&amp;gt;;
%if %sysfunc(exist(&amp;lt;DATASET_NAME&amp;gt;)) %then %do;
&amp;lt;PUT YOUR DATA STEP HERE&amp;gt;
%end;&amp;nbsp;
%MEND;
&amp;nbsp;
%&amp;lt;MACRONAME&amp;gt;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 07:04:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-a-dataset-exist-or-not/m-p/396176#M95615</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2017-09-15T07:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: Check a dataset exist or not</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-a-dataset-exist-or-not/m-p/396204#M95629</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139803"&gt;@R_Chung&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to check whether a dataset exist first then join the dataset with another dataset.&lt;/P&gt;
&lt;P&gt;Below is my code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (exist(ot_reclus_kw_kc)) then do;
    data semi_ot_result; 
	 	set ot_reclus_kw_kc semi_ot_result; 
	 run;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there any errors/mistakes?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, there are &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;if - then - else is data step code (and some procedures also allow such syntax, eg proc report), and can't be used outside of a data step.&lt;/P&gt;
&lt;P&gt;Also keep in mind that data or procedure steps cannot be nested.&lt;/P&gt;
&lt;P&gt;Such problems are best solved by using the macro preprocessor.&lt;/P&gt;
&lt;P&gt;Method 1: do the logic in a data step and save the result to a macro variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
if (exist("ot_reclus_kw_kc"))
then call symput('add_file',"ot_reclus_kw_kc");
else call symput('add_file','');
run;

data semi_ot_result; 
set
  &amp;amp;add_file
  semi_ot_result
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Method 2: use a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro add_file(testfile);
%if %sysfunc(exist(&amp;amp;testfile))
%then %do;
&amp;amp;testfile
%end;
%mend;

data semi_ot_result; 
set
  %add_file(ot_reclus_kw_kc)
  semi_ot_result
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As others have mentioned, rewriting a dataset in the same step can be dangerous and lead to data loss that necessitates a rerun of all previous code.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 08:17:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-a-dataset-exist-or-not/m-p/396204#M95629</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-09-15T08:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: Check a dataset exist or not</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-a-dataset-exist-or-not/m-p/396361#M95685</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139803"&gt;@R_Chung&lt;/a&gt; wrote:&lt;BR /&gt;Is there a missing in hyperlink &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, I assumed that google is sufficient.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use terms "SAS macro check if data exists"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Returns:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/670.html" target="_blank"&gt;http://support.sas.com/kb/24/670.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 14:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-a-dataset-exist-or-not/m-p/396361#M95685</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-15T14:43:09Z</dc:date>
    </item>
  </channel>
</rss>

