<?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 if exist in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SET-if-exist/m-p/726985#M226011</link>
    <description>Thank you.&lt;BR /&gt;As I understand the condition :  prxmatch('/tbl\d{8}/i',MEMNAME) &lt;BR /&gt;is checking which data set name contain the substring "tbl" .&lt;BR /&gt;Can you explain please why did you write d{8}? (why not d{9} for example)&lt;BR /&gt;</description>
    <pubDate>Wed, 17 Mar 2021 05:45:35 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2021-03-17T05:45:35Z</dc:date>
    <item>
      <title>SET if exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-if-exist/m-p/726280#M225690</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;What is the way to fix the error in example 2.&lt;/P&gt;
&lt;P&gt;I want to set data sets from a list and some of them are not existing.&lt;/P&gt;
&lt;P&gt;May anyone show the code the fix the problem.&lt;/P&gt;
&lt;P&gt;In real life I have many data sets between 2 dates and I want to set them (combine them).&lt;/P&gt;
&lt;P&gt;The problem is that some of them are not existing,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/****example1-All data sets in SET statement exists****/
/****example1-All data sets in SET statement exists****/
/****example1-All data sets in SET statement exists****/
%let start=01032021;
%let end=04032021;

data tbl01032021;
input x y;
cards;
1 10
;
run;

data tbl02032021;
input x y;
cards;
2 11
;
run;

data tbl03032021;
input x y;
cards;
5 18
;
run;

data tbl04032021;
input x y;
cards;
6 16
;
run;

data _null_;
start_char=put(&amp;amp;start.,Z8.-L);
end_char=put(&amp;amp;end.,Z8.-L);
start_sas=mdy(substr(start_char,3,2),substr(start_char,1,2),substr(start_char,5,4));
end_sas=mdy(substr(end_char,3,2),substr(end_char,1,2),substr(end_char,5,4));
format start_sas end_sas  date9.;
counter = intck('day',start_sas,end_sas);
call symputx('n',put(counter,best.));
call symputx('start_sas',put(start_sas,best.));
call symputx('end_sas',put(end_sas,best.));

Run;
%put &amp;amp;n;
%put &amp;amp;start_sas;
%put &amp;amp;end_sas;

%macro months;
%do i=0 %to &amp;amp;n.;
m&amp;amp;i.=put(intnx('day',&amp;amp;start_sas.,&amp;amp;i.),ddmmyyn8.);
call symputx("m&amp;amp;i",trim(left(m&amp;amp;i.)));
%end;
%mend;

data series_days;
%months;
run;
%put &amp;amp;n;
%put &amp;amp;m0;
%PUT &amp;amp;&amp;amp;m&amp;amp;n..;

%macro sset; 
%do j=0 %to &amp;amp;n.;
tbl&amp;amp;&amp;amp;m&amp;amp;j..
%end;
%mend sset;
%put %sset;

Data wanted;
SET %sset;
Run;


/****example2-Set if exist ****/
/****example2-Set if exist ****/
/****example2-Set if exist ****/
%let start=01032021;
%let end=06032021;

data ttt01032021;
input x y;
cards;
1 10
;
run;

data ttt02032021;
input x y;
cards;
2 11
;
run;

data ttt03032021;
input x y;
cards;
5 18
;
run;

data ttt06032021;
input x y;
cards;
6 16
;
run;

data _null_;
start_char=put(&amp;amp;start.,Z8.-L);
end_char=put(&amp;amp;end.,Z8.-L);
start_sas=mdy(substr(start_char,3,2),substr(start_char,1,2),substr(start_char,5,4));
end_sas=mdy(substr(end_char,3,2),substr(end_char,1,2),substr(end_char,5,4));
format start_sas end_sas  date9.;
counter = intck('day',start_sas,end_sas);
call symputx('n',put(counter,best.));
call symputx('start_sas',put(start_sas,best.));
call symputx('end_sas',put(end_sas,best.));

Run;
%put &amp;amp;n;
%put &amp;amp;start_sas;
%put &amp;amp;end_sas;

%macro months;
%do i=0 %to &amp;amp;n.;
m&amp;amp;i.=put(intnx('day',&amp;amp;start_sas.,&amp;amp;i.),ddmmyyn8.);
call symputx("m&amp;amp;i",trim(left(m&amp;amp;i.)));
%end;
%mend;

data series_days;
%months;
run;
%put &amp;amp;n;
%put &amp;amp;m0;
%PUT &amp;amp;&amp;amp;m&amp;amp;n..;

%macro sset; 
%do j=0 %to &amp;amp;n.;
ttt&amp;amp;&amp;amp;m&amp;amp;j..
%end;
%mend sset;
%put %sset;

Data wanted;
SET %sset;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Mar 2021 13:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-if-exist/m-p/726280#M225690</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-03-15T13:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: SET if exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-if-exist/m-p/726389#M225697</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;%let start=01032021;
%let end=04032021;

proc sql noprint;
		select MEMNAME into :ds separated by ' ' from dictionary.tables
		where prxmatch('/tbl\d{8}/i',MEMNAME) and LIBNAME = 'WORK' 
	    and input("&amp;amp;start",MMDDYY8.)  &amp;lt;= input(compress(MEMNAME,,'a'),MMDDYY8.) &amp;lt;= input("&amp;amp;end",MMDDYY8.);
quit;

data all;
	set &amp;amp;ds;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Mar 2021 14:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-if-exist/m-p/726389#M225697</guid>
      <dc:creator>Athenkosi</dc:creator>
      <dc:date>2021-03-15T14:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: SET if exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-if-exist/m-p/726391#M225698</link>
      <description>&lt;P&gt;It is hard to tell what your actual problem is.&amp;nbsp; But if you want to check if a dataset exists then use the EXISTS() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looks like your dataset names include a date component.&amp;nbsp; If your issue is you want find all of the datasets that exist between two dates then just use a DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start=01032021;
%let end=04032021;

data _null_;
  start = input("&amp;amp;start",ddmmyy8.);
  end = input("&amp;amp;end",ddmmyy8.);
  format start end  date9.;
  counter=0;
  length dsname $41 ;
  do date=start to end ;
    dsname = cats('ttt',put(date,ddmmyyn8.));
    if exists(dsname) then do;
       counter+1;
       call symputx(cats('ds',counter),dsname);
    end;
  end;
  call symputx('counter',counter);
run;

data want;
  length dsname $41 ;
  set 
%do index=1 %to &amp;amp;counter ;
  &amp;amp;&amp;amp;ds&amp;amp;index
%end;
    indsname=dsname
  ;
  date = input(substr(dsname,length(dsname)-7),ddmmyy8.);
  format date date9.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 14:50:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-if-exist/m-p/726391#M225698</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-15T14:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: SET if exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-if-exist/m-p/726401#M225700</link>
      <description>&lt;P&gt;I strongly suggest that you consider what might happen when you just let macro variables "fall into" you code like in this&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;%macro months;
%do i=0 %to &amp;amp;n.;
m&amp;amp;i.=put(intnx('day',&amp;amp;start_sas.,&amp;amp;i.),ddmmyyn8.);
call symputx("m&amp;amp;i",trim(left(m&amp;amp;i.)));
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You have two macro variables that are not defined with the macro. Which means you have no way of ensuring when you call the macro that a value exists or is the expected value.&lt;/P&gt;
&lt;P&gt;Macros provide for parameters for a reason and including things your code expects to use will help you remember to provide the values, or defaults if they have not been set yet. It also helps control scope so one call to a macro doesn't accidentally change the value needed elsewhere.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 14:42:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-if-exist/m-p/726401#M225700</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-15T14:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: SET if exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-if-exist/m-p/726985#M226011</link>
      <description>Thank you.&lt;BR /&gt;As I understand the condition :  prxmatch('/tbl\d{8}/i',MEMNAME) &lt;BR /&gt;is checking which data set name contain the substring "tbl" .&lt;BR /&gt;Can you explain please why did you write d{8}? (why not d{9} for example)&lt;BR /&gt;</description>
      <pubDate>Wed, 17 Mar 2021 05:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-if-exist/m-p/726985#M226011</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-03-17T05:45:35Z</dc:date>
    </item>
  </channel>
</rss>

