<?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 Merge with mutiple of data sets or merge with one stacked data set? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746110#M234022</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a data set called Transcation_tbl with following fields: Cusomer_ID, date,YYMM,transaction_ID,Amount.&lt;/P&gt;
&lt;P&gt;Date is date of transaction (SAS date).&lt;/P&gt;
&lt;P&gt;YYMM is a char in structure YYMM&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are series of data sets called tYYMM with following columns:&amp;nbsp;Cusomer_ID,wealth,Obligation.&lt;/P&gt;
&lt;P&gt;The task is to add :wealth,Obligation to data set&amp;nbsp;&amp;nbsp;Transcation_tbl .&lt;/P&gt;
&lt;P&gt;There are 2 ways to do it and I want to ask which way is better:&lt;/P&gt;
&lt;P&gt;Way1:&lt;/P&gt;
&lt;P&gt;Create one data set by stacking (union) data sets&amp;nbsp;tYYMM and add a column called YYMM(Take it from the source data set name).&lt;/P&gt;
&lt;P&gt;Then Perform merge&amp;nbsp; Transcation_tbl + Stcked_tbl (Left Join) By&amp;nbsp;Cusomer_ID+YYMM.&lt;/P&gt;
&lt;P&gt;Please note that in this way the stacked data set will contain many rows(maybe 200 million rows)&lt;/P&gt;
&lt;P&gt;Way2:&lt;/P&gt;
&lt;P&gt;Merge&amp;nbsp;Transcation_tbl +multiple data sets&amp;nbsp; tYYMM (Left Join)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which way is better?&lt;/P&gt;
&lt;P&gt;Is there another way more efficient?&lt;/P&gt;
&lt;P&gt;Will it save time If I define index for data sets?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 06 Jun 2021 19:49:24 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2021-06-06T19:49:24Z</dc:date>
    <item>
      <title>Merge with mutiple of data sets or merge with one stacked data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746110#M234022</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a data set called Transcation_tbl with following fields: Cusomer_ID, date,YYMM,transaction_ID,Amount.&lt;/P&gt;
&lt;P&gt;Date is date of transaction (SAS date).&lt;/P&gt;
&lt;P&gt;YYMM is a char in structure YYMM&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are series of data sets called tYYMM with following columns:&amp;nbsp;Cusomer_ID,wealth,Obligation.&lt;/P&gt;
&lt;P&gt;The task is to add :wealth,Obligation to data set&amp;nbsp;&amp;nbsp;Transcation_tbl .&lt;/P&gt;
&lt;P&gt;There are 2 ways to do it and I want to ask which way is better:&lt;/P&gt;
&lt;P&gt;Way1:&lt;/P&gt;
&lt;P&gt;Create one data set by stacking (union) data sets&amp;nbsp;tYYMM and add a column called YYMM(Take it from the source data set name).&lt;/P&gt;
&lt;P&gt;Then Perform merge&amp;nbsp; Transcation_tbl + Stcked_tbl (Left Join) By&amp;nbsp;Cusomer_ID+YYMM.&lt;/P&gt;
&lt;P&gt;Please note that in this way the stacked data set will contain many rows(maybe 200 million rows)&lt;/P&gt;
&lt;P&gt;Way2:&lt;/P&gt;
&lt;P&gt;Merge&amp;nbsp;Transcation_tbl +multiple data sets&amp;nbsp; tYYMM (Left Join)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which way is better?&lt;/P&gt;
&lt;P&gt;Is there another way more efficient?&lt;/P&gt;
&lt;P&gt;Will it save time If I define index for data sets?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jun 2021 19:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746110#M234022</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-06-06T19:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with mutiple of data sets or merge with one stacked data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746139#M234029</link>
      <description>&lt;P&gt;Do we have any assumptions about &lt;SPAN&gt;Transcation_tbl? Is it sorted (if yes, how?), is it indexed? Is, and if yes how, the YYMM related to date?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How many datasets tYYMM do you have?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Bart&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jun 2021 22:17:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746139#M234029</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-06-06T22:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with mutiple of data sets or merge with one stacked data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746140#M234030</link>
      <description>&lt;P&gt;Give us a few usable examples for the TYYMM and transaction_tbl datasets, covering all constellations appearing in your real data, and the result you expect from that.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jun 2021 22:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746140#M234030</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-06T22:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with mutiple of data sets or merge with one stacked data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746200#M234061</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;&amp;nbsp;&lt;BR /&gt;1.If your data is in&amp;nbsp; RBMS tables, as much as possible use the native SQL, So SQL Pass through an native SQL syntax.&lt;/P&gt;
&lt;P&gt;2.The first approach looks more comprehensible an I would prefer it.&amp;nbsp;&lt;BR /&gt;3.Both approaches come with a cost, but the first one will be easy to manage.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 11:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746200#M234061</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-06-07T11:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with mutiple of data sets or merge with one stacked data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746282#M234094</link>
      <description>&lt;P&gt;Neither IMO.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should APPEND your data not join it in, ie use a UNION. If you have a column for every month, that means every month you're adding a new column to your DB not just extra rows which adds work to your process. And SQL and other languages can easily flip it. Also, you can then index your data by date making it easier to query as that's most likely the best way to filter your data in the long run. A wide format is used for reporting, but very, very rarely for data storage in my 20 years of experience.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 15:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746282#M234094</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-07T15:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with mutiple of data sets or merge with one stacked data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746984#M234410</link>
      <description>&lt;BR /&gt;Is it sorted (if yes, how?), is it indexed?Yes, It is sorted, No, It has no Index&lt;BR /&gt;&lt;BR /&gt; Is, and if yes how, the YYMM related to date?&lt;BR /&gt;How many datasets tYYMM do you have? In real there are 24 data sets of tYYM (each data set contain around 5 million rows)&lt;BR /&gt; &lt;BR /&gt;Bart&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Jun 2021 10:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746984#M234410</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-06-10T10:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with mutiple of data sets or merge with one stacked data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746986#M234412</link>
      <description>&lt;P&gt;Hello all, please see current code.&lt;/P&gt;
&lt;P&gt;In real life there are many fields to tYYMM data sets .&lt;/P&gt;
&lt;P&gt;In real life there are many data sets tYYMM(50&amp;nbsp; data sets that are produced every month).&lt;/P&gt;
&lt;P&gt;Question:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May anyone show other attitudes that are more efficient and explain why they are more efficient?&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;
Data Transcation_tbl;
format date date9.;
Input Cusomer_ID  date :date9. YYMM $  transaction_ID  Amount;
cards;
1 27Apr2021 2103 123456 1000
2 22Mar2021 2101 345677 2000
3 01Jan2021 2012 763372 3000
;
Run;

Data t2012;
input Cusomer_ID wealth Obligation;
cards;
1 100 10
2 200 20
3 100 0
4 400 30
5 200 20
6 500 50
;
run;

Data t2101;
input Cusomer_ID wealth Obligation;
cards;
1 200 20
2 100 30
3 300 10
4 200 0
5 500 0
6 400 25
;
run;


Data t2102;
input Cusomer_ID wealth Obligation;
cards;
1 300 10
3 200 20
6 300 30
;
run;



Data t2103;
input Cusomer_ID wealth Obligation;
cards;
1 200 40
3 200 20
4 500 50
6 300 30
;
run;

PROC SQL noprint;
	select  min(YYMM),max(YYMM) into: minYYMM , :maxYYMM	   
	from  Transcation_tbl
;
QUIT;
%put &amp;amp;minYYMM;
%put &amp;amp;maxYYMM;


data _null_;
  date_start=mdy(mod(&amp;amp;minYYMM,100),1,floor(&amp;amp;minYYMM/100));
  date_end=mdy(mod(&amp;amp;maxYYMM,100),1,floor(&amp;amp;maxYYMM/100));
  format date_start date_end  date9.;
  counter = intck('month',date_start,date_end);
  call symputx('n',put(counter,best.));
  call symputx('date_start',put(date_start,best.));
run;
%put &amp;amp;n.;

%macro months;
%do i=0 %to &amp;amp;n.;
     m&amp;amp;i.=put(intnx('month',&amp;amp;date_start.,&amp;amp;i.),yymmn4.);
     call symputx("m&amp;amp;i",trim(left(m&amp;amp;i.)));
%end;
%mend;

data _null_;
%months;
run;

%put &amp;amp;n;
%put &amp;amp;m0;
%PUT &amp;amp;&amp;amp;m&amp;amp;n..;



%macro ssort;
%do j=0 %to &amp;amp;n.;
proc sort data=t&amp;amp;&amp;amp;m&amp;amp;j..;by Cusomer_ID;Run;
%end;	
%mend ssort;
%ssort;


%macro mmerge;
%do j=0 %to &amp;amp;n.;
t&amp;amp;&amp;amp;m&amp;amp;j..(rename=(wealth=wealth&amp;amp;&amp;amp;m&amp;amp;j.. Obligation=Obligation&amp;amp;&amp;amp;m&amp;amp;j..))
%end;
%mend mmerge;
%put %mmerge;


%macro dropp;
%do j=0 %to &amp;amp;n.;
wealth&amp;amp;&amp;amp;m&amp;amp;j.. 
Obligation&amp;amp;&amp;amp;m&amp;amp;j..
%end;	
%mend;


%macro scorinit;
%do j=0 %to &amp;amp;n.;
if YYMM=&amp;amp;&amp;amp;m&amp;amp;j.. then do;
wealth_H=wealth&amp;amp;&amp;amp;m&amp;amp;j..;
Obligation_H=Obligation&amp;amp;&amp;amp;m&amp;amp;j..;
end;
%end;
%mend;

proc sort data=Transcation_tbl;by Cusomer_ID;Run;
data halvaot400d (drop=%dropp);
merge Transcation_tbl(in=a) %mmerge;
by Cusomer_ID;
%scorinit;
if a;
run; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Jun 2021 11:10:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746986#M234412</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-06-10T11:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with mutiple of data sets or merge with one stacked data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746989#M234415</link>
      <description>May you please also show code? thank you</description>
      <pubDate>Thu, 10 Jun 2021 11:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-mutiple-of-data-sets-or-merge-with-one-stacked-data/m-p/746989#M234415</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-06-10T11:23:42Z</dc:date>
    </item>
  </channel>
</rss>

