<?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: Merge if data sets exists in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-if-data-sets-exists/m-p/738389#M230330</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The values of macro variable YYYYMMDD start with "&lt;FONT face="courier new,courier"&gt;t&lt;/FONT&gt;" so that your references&amp;nbsp;&lt;FONT face="courier new,courier"&gt;t&amp;amp;YYYYMMDD.&lt;/FONT&gt; resolve to names starting with "&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;tt&lt;/FONT&gt;&lt;/STRONG&gt;" and no such datasets exist. So, either exclude the "&lt;FONT face="courier new,courier"&gt;t&lt;/FONT&gt;" from &lt;FONT face="courier new,courier"&gt;YYYYMMDD&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;%let YYYYMMDD=&lt;STRONG&gt;%substr(&lt;/STRONG&gt;%scan(&amp;amp;List.,&amp;amp;j.,+)&lt;STRONG&gt;,2)&lt;/STRONG&gt;;&lt;/PRE&gt;
&lt;P&gt;(note that this has an impact on the new dataset name &lt;FONT face="courier new,courier"&gt;new&amp;amp;YYYYMMDD.&lt;/FONT&gt;) or simply remove the prefix "&lt;FONT face="courier new,courier"&gt;t&lt;/FONT&gt;" where it precedes macro variable references&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;amp;YYYYMMDD.&lt;/FONT&gt; (in three places in your code).&lt;/P&gt;</description>
    <pubDate>Sun, 02 May 2021 11:42:43 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-05-02T11:42:43Z</dc:date>
    <item>
      <title>Merge if data sets exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-if-data-sets-exists/m-p/738381#M230322</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to merge data sets only if they exists (to prevent error).&lt;/P&gt;
&lt;P&gt;Why this code is not working please?&lt;/P&gt;
&lt;P&gt;May anyone show the way to solve the problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data t01042021;
input Id x;
cards;
1 10
2 15
;
run;

Data t03042021;
input Id x;
cards;
3 14
2 16
;
run;

Data t07042021;
input Id x;
cards;
4 17
1 28
;
run;


%let list=t01042021+t02042021+t03042021+t04042021+t05042021+t06042021+t07042021;
%let n=7;&lt;BR /&gt;
Data customers;
input ID ;
cards;
1
2
;
Run;


%macro ttt; 
%do j=1 %to &amp;amp;n.;
%let YYYYMMDD=%scan(&amp;amp;List.,&amp;amp;j.,+);
%if %sysfunc(exist(t&amp;amp;YYYYMMDD.)) %then %do;   
proc sort data=t&amp;amp;YYYYMMDD.;by ID;Run;
proc sort data=customers ;by ID;Run;
Data new&amp;amp;YYYYMMDD.;
merge t&amp;amp;YYYYMMDD.(in=a)customers(in=b);
by ID;
IF a and b;
Run;
%end;
%end;
%mend ttt;
%ttt; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 May 2021 10:39:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-if-data-sets-exists/m-p/738381#M230322</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-05-02T10:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: Merge if data sets exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-if-data-sets-exists/m-p/738389#M230330</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The values of macro variable YYYYMMDD start with "&lt;FONT face="courier new,courier"&gt;t&lt;/FONT&gt;" so that your references&amp;nbsp;&lt;FONT face="courier new,courier"&gt;t&amp;amp;YYYYMMDD.&lt;/FONT&gt; resolve to names starting with "&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;tt&lt;/FONT&gt;&lt;/STRONG&gt;" and no such datasets exist. So, either exclude the "&lt;FONT face="courier new,courier"&gt;t&lt;/FONT&gt;" from &lt;FONT face="courier new,courier"&gt;YYYYMMDD&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;%let YYYYMMDD=&lt;STRONG&gt;%substr(&lt;/STRONG&gt;%scan(&amp;amp;List.,&amp;amp;j.,+)&lt;STRONG&gt;,2)&lt;/STRONG&gt;;&lt;/PRE&gt;
&lt;P&gt;(note that this has an impact on the new dataset name &lt;FONT face="courier new,courier"&gt;new&amp;amp;YYYYMMDD.&lt;/FONT&gt;) or simply remove the prefix "&lt;FONT face="courier new,courier"&gt;t&lt;/FONT&gt;" where it precedes macro variable references&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;amp;YYYYMMDD.&lt;/FONT&gt; (in three places in your code).&lt;/P&gt;</description>
      <pubDate>Sun, 02 May 2021 11:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-if-data-sets-exists/m-p/738389#M230330</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-05-02T11:42:43Z</dc:date>
    </item>
  </channel>
</rss>

