<?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: Proc sql : add the rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901254#M356173</link>
    <description>&lt;P&gt;Sorry, the IS_KEY are not missing, it's not ".". I would like to add the rows (by NO_POLICE and D_VAL) to table a if for this rows I have the different IS_KEY in table b. I would like to do this kind of join :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tab_complet;
	merge Tab2(in=IN1) HISTO(in=IN2);
	by NO_1 IS_key D_VAL;
	if NO_1 (IN1=1 and IN2=1)  and IS_key (IN1=0 and IN2=1) and  D_VAL (IN1=1 and IN2=1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 02 Nov 2023 15:42:40 GMT</pubDate>
    <dc:creator>SASdevAnneMarie</dc:creator>
    <dc:date>2023-11-02T15:42:40Z</dc:date>
    <item>
      <title>Proc sql : add the rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901237#M356165</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to join the rows with only the b.IS_KEY that are not in table a, how to rewrite this code :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table Tab_complet as select a.*, b.* from Tab2
		left join HISTO as b on a.NO_1 =b.NO_1 and
 a.IS_key=b.IS_key and a.D_VAL=b.D_VAL;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would like to add to the table a the missing IS_key from table b, or, with proc sort, I would like to do this :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tab_complet;
	merge Tab2(in=IN1) HISTO(in=IN2);
	by NO_1 IS_key D_VAL;
	if NO_1 (IN1=1 and IN2=1)  and IS_key (IN1=0 and IN2=1) and  D_VAL (IN1=1 and IN2=1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I other words, I would like to merge tab1+tab2 by X1 not eq X2 and X3 to have the result the tab3 :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data tab1;
input X1 X2 X3;
cards;
1 3 8
2 3 7
3 4 6
4 5 7
;
run;

data tab2;
input X1 X2 X3;
cards;
1 3 8
2 5 7
3 6 7
4 5 7
;
run;


data tab3;
input X1 X2 X3;
cards;
1 3 8
2 3 7
2 5 7
3 4 6
4 5 7
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Nov 2023 16:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901237#M356165</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2023-11-02T16:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql : add the rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901238#M356166</link>
      <description>&lt;P&gt;Please explain what is wrong with the code you show. Please show us examples of your data sets (these could be totally fake data as long as the variable names and organization of the data is the same). Show us the data as WORKING data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;), which was done by someone else in your &lt;A href="https://communities.sas.com/t5/SAS-Programming/Last-week-day-before-the-date/m-p/900282#M355808" target="_self"&gt;other thread&lt;/A&gt;. Do not provide data in any other format.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 14:20:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901238#M356166</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-02T14:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql : add the rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901239#M356167</link>
      <description>&lt;P&gt;If you have IS_KEY variable in both tables, and wanted to copy values from Table B to Table A (where missing) then COALESCE function works for you. Something like this should work.&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
	create table Tab_complet as 
               select a.*, b.* , coalesce(a.IS_KEY, b.IS_KEY) 
                     from Tab2 as a
		            left join 
                      HISTO as b 
                 on a.NO_1 =b.NO_1
         and  a.D_VAL=b.D_VAL;
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Nov 2023 14:20:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901239#M356167</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-11-02T14:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql : add the rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901244#M356169</link>
      <description>&lt;P&gt;Thank you, A_Kh, this is what I want but the result of your code is a full join. I would like to add the missing IS_SUPPORT values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 14:40:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901244#M356169</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2023-11-02T14:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql : add the rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901253#M356172</link>
      <description>&lt;P&gt;Without data I could only guess, and my guess is in your SELECT clause you don't need b.*. If you need only&amp;nbsp;&lt;SPAN&gt;IS_SUPPORT&amp;nbsp;values from Table B then try to join only this into Table A.&lt;BR /&gt;What if you try this:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;proc sql;
	create table Tab_complet (drop n1 dval) as 
               select a.*, coalesce(a.IS_KEY, b.IS_KEY) as NEW_KEY
                     from Tab2 as a
		            left join 
                      (select IS_KEY, NO_1 as n1, D_VAL as dval from HISTO) as b 
                 on a.NO_1 =b.n1
         and a.D_VAL=b.dval;
quit;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 15:10:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901253#M356172</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-11-02T15:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql : add the rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901254#M356173</link>
      <description>&lt;P&gt;Sorry, the IS_KEY are not missing, it's not ".". I would like to add the rows (by NO_POLICE and D_VAL) to table a if for this rows I have the different IS_KEY in table b. I would like to do this kind of join :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tab_complet;
	merge Tab2(in=IN1) HISTO(in=IN2);
	by NO_1 IS_key D_VAL;
	if NO_1 (IN1=1 and IN2=1)  and IS_key (IN1=0 and IN2=1) and  D_VAL (IN1=1 and IN2=1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Nov 2023 15:42:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901254#M356173</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2023-11-02T15:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql : add the rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901267#M356177</link>
      <description>Thank you, I updated my message.</description>
      <pubDate>Thu, 02 Nov 2023 16:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901267#M356177</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2023-11-02T16:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql : add the rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901269#M356179</link>
      <description>&lt;P&gt;I do not understand how you got TAB3 from from TAB1 and TAB2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have all of the observations from TAB1 but have added only one of the observations from TAB2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two of the observations you eliminated appear to be exact duplicates of existing observations in TAB1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But why did you add only one of the two new observations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 17:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901269#M356179</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-02T17:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql : add the rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901275#M356180</link>
      <description>Thank you for your message. The line with data 2 5 7 doesn’t exist in table 1. This line match by x1 and x3 so I added this line.</description>
      <pubDate>Thu, 02 Nov 2023 17:38:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901275#M356180</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2023-11-02T17:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql : add the rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901283#M356181</link>
      <description>&lt;P&gt;So union TAB1 with the records from TAB2 that match TAB1 values of X1 and X3.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
 create table want as 
 select * from tab1
 union
 select tab2.* from tab2 inner join tab1 on tab1.x1=tab2.x1 and tab1.x3=tab2.x3
 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Nov 2023 18:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901283#M356181</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-02T18:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql : add the rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901300#M356193</link>
      <description>&lt;P&gt;Thank you. Unfortunately, my real data is not the same, the columns are different, I can't do union. I have onle the same 3 keys for join. Actually, I would like to this :&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tab_complet;
	merge Tab2(in=IN1) HISTO(in=IN2);
	by NO_1 IS_key D_VAL;
	if NO_1 (IN1=1 and IN2=1)  and IS_key (IN1=0 and IN2=1) and  D_VAL (IN1=1 and IN2=1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Nov 2023 20:57:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901300#M356193</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2023-11-02T20:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql : add the rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901313#M356203</link>
      <description>&lt;P&gt;Not sure I understand.&amp;nbsp; How can you add observations if the datasets have different variables?&amp;nbsp; That are you putting into the new observations in that case?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Provide a clearer example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you just need to make the subset of the second dataset first before trying to append/merge it with the first dataset?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 22:33:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-add-the-rows/m-p/901313#M356203</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-02T22:33:50Z</dc:date>
    </item>
  </channel>
</rss>

