<?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: Update unmatched missing values from left join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721460#M223620</link>
    <description>Thanks for your quick reply, I have updated the dataset to clear any confusion.</description>
    <pubDate>Wed, 24 Feb 2021 03:32:57 GMT</pubDate>
    <dc:creator>SK_11</dc:creator>
    <dc:date>2021-02-24T03:32:57Z</dc:date>
    <item>
      <title>Update unmatched missing values from left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721420#M223594</link>
      <description>&lt;P&gt;I have the following&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have1;&lt;BR /&gt;input Grp cum ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2&lt;BR /&gt;2 4&lt;BR /&gt;3 6&lt;BR /&gt;4 8&lt;BR /&gt;5 10&lt;BR /&gt;6 12&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have2;&lt;BR /&gt;input id ;&lt;BR /&gt;datalines;&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;4&lt;BR /&gt;5&lt;BR /&gt;6&lt;BR /&gt;7&lt;BR /&gt;8&lt;BR /&gt;9&lt;BR /&gt;10&lt;BR /&gt;11&lt;BR /&gt;12&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;Create table want as&lt;BR /&gt;Select a.Id,&lt;BR /&gt;b.Grp&lt;BR /&gt;from have2 as a&lt;BR /&gt;left join have1 as b&lt;BR /&gt;on a.id=b.Cum&lt;BR /&gt;;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border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;Grp&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 23:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721420#M223594</guid>
      <dc:creator>SK_11</dc:creator>
      <dc:date>2021-02-23T23:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: Update unmatched missing values from left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721433#M223604</link>
      <description>&lt;P&gt;SQL is not really the solution for this but here you go:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
	input Grp cum;
	datalines;
1 2
2 4
3 6
4 8
5 10
6 12
;
run;

data have2;
	input id;
	datalines;
1
2
3
4
5
6
7
8
9
10
11
12
;
run;

proc sql;
	Create table want (keep=id grp) as
		Select a.Id,
			b.Grp as grp_,
		case 
			when b.grp is missing then monotonic() - 1 
		end 
	as col,
		case 
			when b.grp is missing then sum(1,calculated col) 
			else b.grp 
		end 
	as grp
		from have2 as a
			left join have1 as b
				on a.id=b.Cum;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Feb 2021 00:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721433#M223604</guid>
      <dc:creator>qoit</dc:creator>
      <dc:date>2021-02-24T00:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Update unmatched missing values from left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721434#M223605</link>
      <description>&lt;P&gt;What is the reasoning that says ID=1 should be matched to GRP=1? I do not see the connection.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 00:57:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721434#M223605</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-24T00:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: Update unmatched missing values from left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721441#M223607</link>
      <description>&lt;P&gt;There is no relationship between group and id. This is a mere representation of more than 100K rows.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 01:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721441#M223607</guid>
      <dc:creator>SK_11</dc:creator>
      <dc:date>2021-02-24T01:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Update unmatched missing values from left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721459#M223619</link>
      <description>&lt;P&gt;To remove the confusion here is the updated data set.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have1;&lt;BR /&gt;input Grp cum ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 3252&lt;BR /&gt;2 6752&lt;BR /&gt;3 10252&lt;BR /&gt;4 13752&lt;BR /&gt;5 17252&lt;BR /&gt;6 20752&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have2;&lt;BR /&gt;do i=1 to 20000;&lt;BR /&gt;id=i;output;&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 03:30:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721459#M223619</guid>
      <dc:creator>SK_11</dc:creator>
      <dc:date>2021-02-24T03:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: Update unmatched missing values from left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721460#M223620</link>
      <description>Thanks for your quick reply, I have updated the dataset to clear any confusion.</description>
      <pubDate>Wed, 24 Feb 2021 03:32:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721460#M223620</guid>
      <dc:creator>SK_11</dc:creator>
      <dc:date>2021-02-24T03:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: Update unmatched missing values from left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721465#M223623</link>
      <description>&lt;P&gt;You must have had some algorithm in your mind when went from your two example input datasets to your desired output dataset.&lt;/P&gt;
&lt;P&gt;What was the logic that said ID=1 was part of GRP=1 instead of GRP=2 or 3 or 3457?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 04:24:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721465#M223623</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-24T04:24:36Z</dc:date>
    </item>
    <item>
      <title>Re: Update unmatched missing values from left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721468#M223625</link>
      <description>&lt;P&gt;I am trying to fill up the missing group values when I left join. The desired output will be all ids less than cum should have the same group value.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 04:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721468#M223625</guid>
      <dc:creator>SK_11</dc:creator>
      <dc:date>2021-02-24T04:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: Update unmatched missing values from left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721471#M223627</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/50302"&gt;@SK_11&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to fill up the missing group values when I left join. The desired output will be all ids less than cum should have the same group value.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There must be more to it than that.&amp;nbsp; If HAVE1 is&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
  input Grp cum;
datalines;
1 2
2 4
3 6
4 8
5 10
6 12
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The ID=1 will be a member of all 6 GRP values since one is less than 2 and also less than 4 and less then 6 etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why would you want to try to force a solution to this problem using SQL?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 04:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721471#M223627</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-24T04:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: Update unmatched missing values from left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721473#M223628</link>
      <description>&lt;P&gt;Do you just want to do this?&lt;/P&gt;
&lt;P&gt;Given this input:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
  input Grp cum;
datalines;
1 2
2 4
3 6
4 8
5 10
6 12
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Run this data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have1;
  do id=sum(lag(cum),1) to cum;
     output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs    Grp    cum    id

  1     1       2     1
  2     1       2     2
  3     2       4     3
  4     2       4     4
  5     3       6     5
  6     3       6     6
  7     4       8     7
  8     4       8     8
  9     5      10     9
 10     5      10    10
 11     6      12    11
 12     6      12    12
&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Feb 2021 04:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721473#M223628</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-24T04:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Update unmatched missing values from left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721475#M223630</link>
      <description>Thanks for your quick reply. Any solutions would be fine. I have given a SQL example to show the missing values when I left join. I am interested to fill up the missing values of the group column where ids are less than the matched ids. I have updated the example data set as&lt;BR /&gt;data have1;&lt;BR /&gt;input Grp cum ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 3252&lt;BR /&gt;2 6752&lt;BR /&gt;3 10252&lt;BR /&gt;4 13752&lt;BR /&gt;5 17252&lt;BR /&gt;6 20752&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data have2;&lt;BR /&gt;do i=1 to 20000;&lt;BR /&gt;id=i;output;&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 24 Feb 2021 04:48:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721475#M223630</guid>
      <dc:creator>SK_11</dc:creator>
      <dc:date>2021-02-24T04:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: Update unmatched missing values from left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721480#M223632</link>
      <description>&lt;P&gt;What does HAVE2 add to the problem?&amp;nbsp; Are you just trying to set an upper bound on the value of ID?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input Grp cum ;
datalines;
1 3252
2 6752
3 10252
4 13752
5 17252
6 20752
;
data want;
  set have1;
  do id=sum(lag(cum),1) to min(cum,20000);
     output;
  end;
run;
proc freq data=want;
  tables grp ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;The FREQ Procedure

                                Cumulative    Cumulative
Grp    Frequency     Percent     Frequency      Percent
--------------------------------------------------------
  1        3252       16.26          3252        16.26
  2        3500       17.50          6752        33.76
  3        3500       17.50         10252        51.26
  4        3500       17.50         13752        68.76
  5        3500       17.50         17252        86.26
  6        2748       13.74         20000       100.00
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 05:50:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721480#M223632</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-24T05:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: Update unmatched missing values from left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721481#M223633</link>
      <description>&lt;P&gt;If you want to "join" HAVE1 and HAVE2 then first convert HAVE1 to something with a range of values of ID.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data groups;
  set have1;
  by cum;
  min=sum(lag(cum),1);
  max=cum;
  keep grp min max;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can join HAVE2 with GROUPS and assign the GRP value to each observation in HAVE2.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table want as
  select * from have2 a inner join groups b
  on a.id between b.min and b.max
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Feb 2021 06:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721481#M223633</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-24T06:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: Update unmatched missing values from left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721494#M223644</link>
      <description>Thanks a lot Tom</description>
      <pubDate>Wed, 24 Feb 2021 08:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-unmatched-missing-values-from-left-join/m-p/721494#M223644</guid>
      <dc:creator>SK_11</dc:creator>
      <dc:date>2021-02-24T08:22:39Z</dc:date>
    </item>
  </channel>
</rss>

