<?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: SET data set if exists in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774737#M246257</link>
    <description>&lt;P&gt;You can do it without a macro nowadays:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data r_r.backup;
set
%if %sysfunc(exist(r_r.panel))
%then %do;
  r_r.panel
%end;
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 17 Oct 2021 16:33:41 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-10-17T16:33:41Z</dc:date>
    <item>
      <title>SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774716#M246250</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I want to create a new data set using set statement.&lt;/P&gt;
&lt;P&gt;IF the data set dosn't exit then I want that nothing will be done(data set will not created) and there will not be an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error is&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;NOTE: Line generated by the invoked macro "IF_EXIST_OLD".
31          r_r.Panel
            ____________________________
            557
ERROR: DATA STEP Component Object failure.  Aborted during the COMPILATION phase.
ERROR 557-185: Variable r_r is not an object.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro if_exist_old;
%if %sysfunc(exist(r_r.Panel)) %then r_r.Panel;
%mend;
Data r_r.Backup;
%if_exist_old;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 Oct 2021 11:08:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774716#M246250</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-10-17T11:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774717#M246251</link>
      <description>&lt;P&gt;You don't have a SET statement in your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is why we advise people to create working SAS code without macros before you try to write a macro. In this case, you need working SAS code for the case where the data set exists, and also working code for the case where the data set doesn't exist. If you had this, you would have a much better chance of achieving your goal of creating code for these situations.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Oct 2021 18:49:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774717#M246251</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-17T18:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774737#M246257</link>
      <description>&lt;P&gt;You can do it without a macro nowadays:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data r_r.backup;
set
%if %sysfunc(exist(r_r.panel))
%then %do;
  r_r.panel
%end;
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 Oct 2021 16:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774737#M246257</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-17T16:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774741#M246259</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You can do it without a macro nowadays:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data r_r.backup;
set
%if %sysfunc(exist(r_r.panel))
%then %do;
  r_r.panel
%end;
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't believe that the OP has SAS 9.4 TS1M5 which I think is required for this to work.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Oct 2021 17:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774741#M246259</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-17T17:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774778#M246269</link>
      <description>That will technically create an empty data set. &lt;BR /&gt;</description>
      <pubDate>Mon, 18 Oct 2021 01:24:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774778#M246269</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-18T01:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774779#M246270</link>
      <description>Modify this example to do your SET instead of PRINT. &lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p011imau3tm4jen1us2a45cyenz9.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p011imau3tm4jen1us2a45cyenz9.htm&lt;/A&gt;</description>
      <pubDate>Mon, 18 Oct 2021 01:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774779#M246270</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-18T01:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774799#M246278</link>
      <description>&lt;P&gt;I am sure you can adept the solution provided provided in your older thread: &lt;A href="https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754937#M238173" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754937#M238173&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 05:35:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774799#M246278</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-10-18T05:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774805#M246279</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;The target is :&lt;/P&gt;
&lt;P&gt;IF data set ABC exist then create a new data set called wanted (using SET statement).&lt;/P&gt;
&lt;P&gt;IF data set ABC doesnt exist then do nothing! (No create empty data set).&lt;/P&gt;
&lt;P&gt;I&amp;nbsp; run this code and get a strange results.&lt;/P&gt;
&lt;P&gt;Data set ABC doesn't exist but I get a data set wanted with following columns&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ronein_0-1634536540695.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64806i87E697138640663E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ronein_0-1634536540695.png" alt="Ronein_0-1634536540695.png" /&gt;&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;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro if_exist_old;
%if %sysfunc(exist(ABC)) %then ABC;
%mend;
Data wanted;
SET
%if_exist_old;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Oct 2021 05:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774805#M246279</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-10-18T05:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774811#M246281</link>
      <description>&lt;P&gt;You need to enclose the whole data step in the macro %IF %THEN %DO - %END block.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 06:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774811#M246281</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-18T06:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774815#M246284</link>
      <description>Sorry I didn't  understand  the problem, may you please  show the code</description>
      <pubDate>Mon, 18 Oct 2021 06:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774815#M246284</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-10-18T06:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774821#M246286</link>
      <description>&lt;P&gt;You already made such code yourself in your other thread (way 1).&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 06:45:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774821#M246286</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-18T06:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774822#M246287</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You can do it without a macro nowadays:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data r_r.backup;
set
%if %sysfunc(exist(r_r.panel))
%then %do;
  r_r.panel
%end;
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;You definitely haven't tested this code. In my environment an "empty" set statement uses _last_ - and using EG there is always a _last_. And with SET also in the macro condition an empty data set gets created.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 06:46:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774822#M246287</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-10-18T06:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774824#M246289</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;Below one way to go.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname r_r "%sysfunc(pathname(work))";
data r_r.panel;
  set sashelp.class;
run;

%macro backup(in=,backup=);
  %if %sysfunc(exist(&amp;amp;in,data)) or %sysfunc(exist(&amp;amp;in,view)) %then
    %do;
      proc datasets lib=%scan(work.&amp;amp;backup,1) nolist nowarn;
        delete %scan(&amp;amp;backup,-1);
        run;
        append
          base=&amp;amp;backup data=&amp;amp;in;
        run;
      quit;
    %end;
%mend;
%backup(in=r_r.panel,backup=r_r.backup)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Oct 2021 07:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774824#M246289</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-10-18T07:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774825#M246290</link>
      <description>&lt;P&gt;I was only showing use of macro code, without regard for the validity of the created code.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 07:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774825#M246290</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-18T07:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774826#M246291</link>
      <description>Yes but my question  was why way2 is not working  well and what is this data set that was created?</description>
      <pubDate>Mon, 18 Oct 2021 07:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774826#M246291</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-10-18T07:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774829#M246294</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Yes but my question was why way2 is not working well and what is this data set that was created?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Read &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;'s post for the details.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 07:12:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774829#M246294</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-18T07:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: SET data set if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774958#M246340</link>
      <description>&lt;P&gt;Example 1 in the &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p1thpm9d6f5itan1c37zh8uz273z.htm#p0d1qrvhcn38zln1o8g9dx60vt6z" target="_self"&gt;exist function documenation&lt;/A&gt;&amp;nbsp;can be changed to achieve what you want&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 17:54:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-set-if-exists/m-p/774958#M246340</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-10-18T17:54:41Z</dc:date>
    </item>
  </channel>
</rss>

