<?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: Combination of sets in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Combination-of-sets/m-p/260699#M7133</link>
    <description>&lt;P&gt;Oh sorry, it was just an exemple what i post here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But i have translate the picture into code :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lib.montant1206;
format id $3. mt_1 9.2 mt_2 9.2 mt_3 9.2 mt_4  9.2 mt_5 9.2 mt_6  9.2 mt7 9.2 mt_8 9.2 mt_9 9.2;
input id mt_1 mt_2 mt_3 mt_4 mt_5 mt_6 mt7 mt_8 mt_9;
cards;
a12 1 . . . . . . . .
a13 . 2 . . . . . . .
a14 . . . . 4 . . . .
a15 . . . . . . . . .
a16 3 . . . . . . . . 
;


data lib.montant1207;
format id $3. mt_1 9.2 mt_2 9.2 mt_3 9.2 mt_4  9.2 mt_5 9.2 mt_6  9.2 mt7 9.2 mt_8 9.2 mt_9 9.2;
input id mt_1 mt_2 mt_3 mt_4 mt_5 mt_6 mt7 mt_8 mt_9;
cards;
a12 . 2 . . . . . . .
a13 . . 3 . . . . . .
a14 . . . . . 6 . . .
a15 7 . . . . . . . .
a16 . 10 . . . . . . . 
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 01 Apr 2016 13:24:21 GMT</pubDate>
    <dc:creator>alisondu77</dc:creator>
    <dc:date>2016-04-01T13:24:21Z</dc:date>
    <item>
      <title>Combination of sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Combination-of-sets/m-p/260689#M7131</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I have a solution to my problem, but I would like something more efficient and quicker.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you can understand&amp;nbsp;on the picture what I want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2586iAA75DA8DCAF42ED7/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Sans titre.png" title="Sans titre.png" /&gt;&lt;/P&gt;&lt;P&gt;I would like to associate two sets (blue and green) or more, to do the red one (it's simply to combination of the 2 sets with null data when there is no number).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So this is my script SAS :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* creation of the set where i save the result */
proc sql ;
create table lib.montant_result as (
select id_dossier, 0 as montant_1, 0 as montant_2,0 as montant_3, 0 as montant_4,
0 as montant_5, 0 as montant_6,0 as montant_7, 0 as montant_8, 0 as montant_9
from lib.clients ;
quit ;


%Macro evolution_montant(YYMM) ;
/* creation of the blue and green sets */
proc sql ;
create table lib.montant_month as (
select id_dossier,
	case when intck("month",date,"01jul2013") = 1 then montant end as montant_1,
	case when intck("month",date,"01jul2013") = 2 then montant end as montant_2,
	case when intck("month",date,"01jul2013") = 3 then montant end as montant_3,
	case when intck("month",date,"01jul2013") = 4 then montant end as montant_4,
	case when intck("month",date,"01jul2013") = 5 then montant end as montant_5,
	case when intck("month",date,"01jul2013") = 6 then montant end as montant_6,
	case when intck("month",date,"01jul2013") = 7 then montant end as montant_7,
	case when intck("month",date,"01jul2013") = 8 then montant end as montant_8,
	case when intck("month",date,"01jul2013") = 9 then montant end as montant_9,
FROM lib.clients clients
inner join lib.montant&amp;amp;YYMM. mont on mont.id_dossier = clients.id_dossier );
quit ; 

/*creation and update of the red set (result) */
proc sql ;
UPDATE lib.montant_result  a
  SET montant_1 = sum(a.montant_1 ,(SELECT b.montant_1 FROM  alison.montant_month  b WHERE a.id_dossier = b.id_dossier )),
   montant_2 = sum(a.montant_2 ,(SELECT b.montant_2 FROM  alison.montant_month  b WHERE a.id_dossier = b.id_dossier )) ,
   montant_3 = sum(a.montant_3 ,(SELECT b.montant_3 FROM  alison.montant_month  b WHERE a.id_dossier = b.id_dossier )) ,
   montant_4 = sum(a.montant_4 ,(SELECT b.montant_4 FROM  alison.montant_month  b WHERE a.id_dossier = b.id_dossier )),
   montant_5 = sum(a.montant_5 ,(SELECT b.montant_5 FROM  alison.montant_month  b WHERE a.id_dossier = b.id_dossier )),
   montant_6 = sum(a.montant_6 ,(SELECT b.montant_6 FROM  alison.montant_month  b WHERE a.id_dossier = b.id_dossier )),
   montant_7 = sum(a.montant_7 ,(SELECT b.montant_7 FROM  alison.montant_month  b WHERE a.id_dossier = b.id_dossier )),
   montant_8 = sum(a.montant_8 ,(SELECT b.montant_8 FROM  alison.montant_month  b WHERE a.id_dossier = b.id_dossier )),
   montant_9 = sum(a.montant_9 ,(SELECT b.montant_9 FROM  alison.montant_month  b WHERE a.id_dossier = b.id_dossier ))
;
quit ;

%mend  evolution_montant;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you in advance. And sorry for my poor english !&lt;BR /&gt;&lt;BR /&gt;Have a good weekend !&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 13:04:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Combination-of-sets/m-p/260689#M7131</guid>
      <dc:creator>alisondu77</dc:creator>
      <dc:date>2016-04-01T13:04:13Z</dc:date>
    </item>
    <item>
      <title>Re: Combination of sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Combination-of-sets/m-p/260690#M7132</link>
      <description>&lt;P&gt;We can't code off pictures though. Please include data as text.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 13:07:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Combination-of-sets/m-p/260690#M7132</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-01T13:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Combination of sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Combination-of-sets/m-p/260699#M7133</link>
      <description>&lt;P&gt;Oh sorry, it was just an exemple what i post here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But i have translate the picture into code :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lib.montant1206;
format id $3. mt_1 9.2 mt_2 9.2 mt_3 9.2 mt_4  9.2 mt_5 9.2 mt_6  9.2 mt7 9.2 mt_8 9.2 mt_9 9.2;
input id mt_1 mt_2 mt_3 mt_4 mt_5 mt_6 mt7 mt_8 mt_9;
cards;
a12 1 . . . . . . . .
a13 . 2 . . . . . . .
a14 . . . . 4 . . . .
a15 . . . . . . . . .
a16 3 . . . . . . . . 
;


data lib.montant1207;
format id $3. mt_1 9.2 mt_2 9.2 mt_3 9.2 mt_4  9.2 mt_5 9.2 mt_6  9.2 mt7 9.2 mt_8 9.2 mt_9 9.2;
input id mt_1 mt_2 mt_3 mt_4 mt_5 mt_6 mt7 mt_8 mt_9;
cards;
a12 . 2 . . . . . . .
a13 . . 3 . . . . . .
a14 . . . . . 6 . . .
a15 7 . . . . . . . .
a16 . 10 . . . . . . . 
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 13:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Combination-of-sets/m-p/260699#M7133</guid>
      <dc:creator>alisondu77</dc:creator>
      <dc:date>2016-04-01T13:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: Combination of sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Combination-of-sets/m-p/260700#M7134</link>
      <description>&lt;P&gt;In light of the test data&amp;amp;colon;&lt;/P&gt;
&lt;PRE&gt;data montant1206;
format id $3. mt_1 9.2 mt_2 9.2 mt_3 9.2 mt_4  9.2 mt_5 9.2 mt_6  9.2 mt7 9.2 mt_8 9.2 mt_9 9.2;
input id mt_1 mt_2 mt_3 mt_4 mt_5 mt_6 mt7 mt_8 mt_9;
cards;
a12 1 . . . . . . . .
a13 . 2 . . . . . . .
a14 . . . . 4 . . . .
a15 . . . . . . . . .
a16 3 . . . . . . . . 
;
run;&lt;BR /&gt;proc transpose data=montant1206 out=t1;&lt;BR /&gt; by id;&lt;BR /&gt; var mt:;&lt;BR /&gt;run;
data montant1207;
format id $3. mt_1 9.2 mt_2 9.2 mt_3 9.2 mt_4  9.2 mt_5 9.2 mt_6  9.2 mt7 9.2 mt_8 9.2 mt_9 9.2;
input id mt_1 mt_2 mt_3 mt_4 mt_5 mt_6 mt7 mt_8 mt_9;
cards;
a12 . 2 . . . . . . .
a13 . . 3 . . . . . .
a14 . . . . . 6 . . .
a15 7 . . . . . . . .
a16 . 10 . . . . . . . 
;
run;
proc transpose data=montant1207 out=t2;
  by id;
  var mt:;
run;

proc sql;
  create table WANT as
  select COALESCE(A.ID,B.ID) as ID,
         COALESCE(A._NAME_,B._NAME_) as MONTH,
         COALESCE(A.COL1,B.COL1) as RESULT
  from   T1 A
  full join T2 B
  on     A.ID=B.ID
  and    A._NAME_=B._NAME_;
quit;&lt;/PRE&gt;
&lt;P&gt;---&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;said. &amp;nbsp;The below is just a guess, but you can use the coalesce() function which takes the first non missing value.&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  COALESCE(A.ID_DOSSIER,B.ID_DOSSIER) as DOSSIER,
            COALESCE(A.MONTANT_1,B.MONTANT_1) as MONTANT_1,
            COALESCE(A.MONTANT_2,B.MONTANT_2) as MONTANT_1,
            ...
  from    HAVE1 A
  full join HAVE2 b
  on       A.ID_DOSSIER=B.DOSSIER;
quit;&lt;/PRE&gt;
&lt;P&gt;But the question here is why not normalise your data, so you have something like:&lt;/P&gt;
&lt;P&gt;ID_DOSSIER &amp;nbsp; MONTH &amp;nbsp; VALUE&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xyz&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xyz&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would then be simple merge statement, and you will find further processing on the data to be far easier than keeping the structure you currently have.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 13:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Combination-of-sets/m-p/260700#M7134</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-01T13:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: Combination of sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Combination-of-sets/m-p/260702#M7135</link>
      <description>&lt;P&gt;UPDATE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
   format id $3.;
   input id mt_1-mt_9;
   cards;
a12 1 . . . . . . . .
a13 . 2 . . . . . . .
a14 . . . . 4 . . . .
a15 . . . . . . . . .
a16 3 . . . . . . . . 
;;;;
data b;
   format id $3.;
   input id mt_1-mt_9;
   cards;
a12 . 2 . . . . . . .
a13 . . 3 . . . . . .
a14 . . . . . 6 . . .
a15 7 . . . . . . . .
a16 . 10 . . . . . . . 
;;;;
   run;
data c;
   update a b;
   by id;
   run;
Proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2590i90B80CA7E682FD4A/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 13:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Combination-of-sets/m-p/260702#M7135</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-04-01T13:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Combination of sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Combination-of-sets/m-p/260707#M7136</link>
      <description>&lt;P&gt;That's exactly what I want ! I didn't know the function "COALESC" !&lt;/P&gt;&lt;P&gt;Thank you so much for your quick and efficient answer !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And to reply to your question, I agree with you but it's not my data and I can not change the dataset.&amp;nbsp;Sets are really to big.&lt;/P&gt;&lt;P&gt;Thank you again !&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 13:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Combination-of-sets/m-p/260707#M7136</guid>
      <dc:creator>alisondu77</dc:creator>
      <dc:date>2016-04-01T13:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Combination of sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Combination-of-sets/m-p/260709#M7137</link>
      <description>&lt;P&gt;You can always change the data You work on, its is irrelevant so long as what goes out is what is required - how you process it is up to you. &amp;nbsp;Anyways, glad you like the coalesce function. &amp;nbsp;I would suggest you alos look at&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__﻿&lt;/a&gt;s suggestion also, especially if you have lots of data and want to keep the structure. &amp;nbsp;Personally I would go normalised, and only transpose at the end.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 13:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Combination-of-sets/m-p/260709#M7137</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-01T13:40:16Z</dc:date>
    </item>
  </channel>
</rss>

