<?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: Macro - left join multiple views in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-left-join-multiple-views/m-p/626484#M184801</link>
    <description>Stack all the data and then transpose them. Use a view for the stacking as well.</description>
    <pubDate>Fri, 21 Feb 2020 15:25:47 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-02-21T15:25:47Z</dc:date>
    <item>
      <title>Macro - left join multiple views</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-left-join-multiple-views/m-p/626475#M184794</link>
      <description>&lt;P&gt;I will be grateful for the answer if it's possible to make below&amp;nbsp;left joining without overwriting values in the last column (col5).&lt;/P&gt;&lt;P&gt;I have proc sql:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; tab3 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a.id1, a.date1, a.col3, a.col4, b.col5&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; tab1 a&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;left&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;join&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; tab_date b &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="2"&gt;/*tab_date - views such as tab_201301, tab_201302,..., tab_202001 */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;on&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a.id1 = b.id1 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;and&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a.date1=b.date1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;I have multiple (quite big) views, from which one&amp;nbsp;I want to join col5. Each view has data for one month. for example: tab_201301 - there are records where column date1 = "31jan2013"d&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;First I thought about&amp;nbsp;concatenate all views, create new table and make left join. But this table will be very large&amp;nbsp;and I am afraid that it will not work.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;I think to create macro:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; example(date_st, period);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%local&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; i date_new;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; date_new = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(inputn(&amp;amp;date_st,yymmn6.));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%to&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysevalf&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(&amp;amp;period);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table tab3 as&lt;/P&gt;&lt;P&gt;select a.id1, a.date1, a.col3, a.col4, b.col5&lt;/P&gt;&lt;P&gt;from tab1 a&lt;/P&gt;&lt;P&gt;left join&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;tab_&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(intnx(month,&amp;amp;date_new,&amp;amp;i),&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;yymmn6.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;b;&lt;/P&gt;&lt;P&gt;on a.id1 = b.id1 and a.date1=b.date1;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it overwrites values in col5.&lt;/P&gt;&lt;P&gt;Is it possible to join views each one&amp;nbsp;without concatenating them first?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 14:43:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-left-join-multiple-views/m-p/626475#M184794</guid>
      <dc:creator>MargoBlue</dc:creator>
      <dc:date>2020-02-21T14:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro - left join multiple views</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-left-join-multiple-views/m-p/626482#M184799</link>
      <description>&lt;P&gt;Since you are trying to do this in a loop, and the data set names follow some sort of regular pattern &lt;FONT face="courier new,courier"&gt;tab_%sysfunc(intnx(month,&amp;amp;date_new,&amp;amp;i),yymmn6.)&lt;/FONT&gt;, you need to do the joins in your loop and rename col5 to &lt;FONT face="courier new,courier"&gt;col5_%sysfunc(intnx(month,&amp;amp;date_new,&amp;amp;i),yymmn6.)&lt;FONT face="arial,helvetica,sans-serif"&gt;, something like this:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select a.id1, a.date1, a.col3, a.col4, 
     b.col5 as col5_%sysfunc(intnx(month,&amp;amp;date_new,&amp;amp;i),yymmn6.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 15:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-left-join-multiple-views/m-p/626482#M184799</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-21T15:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro - left join multiple views</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-left-join-multiple-views/m-p/626484#M184801</link>
      <description>Stack all the data and then transpose them. Use a view for the stacking as well.</description>
      <pubDate>Fri, 21 Feb 2020 15:25:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-left-join-multiple-views/m-p/626484#M184801</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-21T15:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro - left join multiple views</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-left-join-multiple-views/m-p/626486#M184803</link>
      <description>&lt;P&gt;Or better yet, stack all the views and then leave them in the long (rather than wide) form, and then you can do analyses using the a BY statement rather than having to code an analysis for col5_201301 and another for col5_201302&amp;nbsp;&lt;EM&gt;etc&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 15:28:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-left-join-multiple-views/m-p/626486#M184803</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-21T15:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro - left join multiple views</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-left-join-multiple-views/m-p/628772#M185860</link>
      <description>Thank you, it works.</description>
      <pubDate>Mon, 02 Mar 2020 14:15:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-left-join-multiple-views/m-p/628772#M185860</guid>
      <dc:creator>MargoBlue</dc:creator>
      <dc:date>2020-03-02T14:15:36Z</dc:date>
    </item>
  </channel>
</rss>

