<?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 sets IF exits in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754961#M238182</link>
    <description>&lt;P&gt;We have already discussed how to determine if a SAS data set exists in your last thread.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Jul 2021 11:15:11 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-07-19T11:15:11Z</dc:date>
    <item>
      <title>SET data sets IF exits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754937#M238173</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to combine a list of data sets and it might happen that some of them doesnt exist.&lt;/P&gt;
&lt;P&gt;What is the way to change the following statements&amp;nbsp; in order to add the condition ONLY IF EXISTS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace" color="#000000"&gt;&lt;SPAN style="font-size: 14.4px; white-space: pre; background-color: #f5f2f0;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro sset; 
%do j=1 %to &amp;amp;m.;
%let mon=%scan(&amp;amp;vector.,&amp;amp;j.,+);
LGD&amp;amp;mon.  /*How to add the condition only if data set exists*/
%end;
%mend sset;
%put %sset;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&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;Data LGD2101;
Input ID  X;
CARDS;
1 10
2 20
3 30
;
Run;

Data LGD2102;
Input ID  X;
CARDS;
4 10
5 20
7 30
;
Run;

Data LGD2105;
Input ID  X;
CARDS;
8 60
9 40
;
Run;

%let vector=2101+2102+2103+2104+2105;
%let m=5;

%macro sset; 
%do j=1 %to &amp;amp;m.;
%let mon=%scan(&amp;amp;vector.,&amp;amp;j.,+);
LGD&amp;amp;mon.
%end;
%mend sset;
%put %sset;

data LGD_ALL;
SET  %sset_LGD;
Run;


data LGD_ALL;
SET  %sset;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 09:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754937#M238173</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-07-19T09:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: SET data sets IF exits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754945#M238176</link>
      <description>&lt;P&gt;Build actual data set names.&lt;/P&gt;
&lt;P&gt;Search for them in SASHELP.VTABLE or Dictionary.Tables. Remember Memname and Library have to be upper case.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 10:03:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754945#M238176</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-19T10:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: SET data sets IF exits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754961#M238182</link>
      <description>&lt;P&gt;We have already discussed how to determine if a SAS data set exists in your last thread.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 11:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754961#M238182</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-19T11:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: SET data sets IF exits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754965#M238184</link>
      <description>I want to  learn  another method ( different  than SASHELP.VTABLE)&lt;BR /&gt;</description>
      <pubDate>Mon, 19 Jul 2021 11:47:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754965#M238184</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-07-19T11:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: SET data sets IF exits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754969#M238186</link>
      <description>&lt;P&gt;So you don't want to use a method that would work (SASHELP.VTABLE). Why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you also want to not use the method we discussed yesterday? Why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Typically, most people (including me) are happy to know two ways to accomplish a task, in fact one way is enough for me in most cases.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If you have some particular constraints based upon your exact problem, please explain so we don't provide solutions that won't match the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 13:01:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754969#M238186</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-19T13:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: SET data sets IF exits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754973#M238187</link>
      <description>&lt;P&gt;If you want to test if a dataset exists use the EXIST() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro sset; 
%local j dsn;
%if not %symexist(vector) %then %let vector=;
%do j=1 %to %sysfunc(countw(&amp;amp;vector,+));
  %let dsn=LGD%scan(&amp;amp;vector.,&amp;amp;j.,+);
  %if %sysfunc(exist(&amp;amp;dsn)) %then &amp;amp;dsn;
%end;
%mend sset;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Jul 2021 12:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754973#M238187</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-19T12:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: SET data sets IF exits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754997#M238203</link>
      <description>&lt;P&gt;I am looking for a solution that is siamilar to this solution,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in my program it is a bit different because user should define a macro var called vector&amp;nbsp; that contrain dates (YYMM) that need to be set ....May anyone help to adjust the code to my task&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro if_exists(varlist);
%if %sysfunc(exist(%scan(&amp;amp;varlist,1))) %then %scan(&amp;amp;varlist,1);
%mend;

data wanted;
SET
%if_exists(LGD2101)
%if_exists(LGD2102)
%if_exists(LGD2103)
%if_exists(LGD2104)
%if_exists(LGD2105);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 14:29:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754997#M238203</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-07-19T14:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: SET data sets IF exits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/755049#M238208</link>
      <description>&lt;P&gt;Isn't that what other macro does ?&lt;/P&gt;
&lt;P&gt;Here is how I would code it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro if_exist(prefix,list); 
%local j dsn;
%do j=1 %to %sysfunc(countw(&amp;amp;list,+));
  %let dsn=&amp;amp;prefix.%scan(&amp;amp;list.,&amp;amp;j.,+);
  %if %sysfunc(exist(&amp;amp;dsn)) %then &amp;amp;dsn;
%end;
%mend if_exist;

%let vector=2101+2102+2103+2104+2105;
data wanted;
  set %if_exist(prefix=LGD,list=&amp;amp;vector) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 16:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/755049#M238208</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-19T16:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: SET data sets IF exits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/755054#M238212</link>
      <description>Great</description>
      <pubDate>Mon, 19 Jul 2021 17:18:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/755054#M238212</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-07-19T17:18:54Z</dc:date>
    </item>
  </channel>
</rss>

