<?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: Data restructure in sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613391#M179122</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID (Jbcode1 Jbcode2 Jbcode30) ($);
cards;
101 AA     . .     
101   .          BB .
101   .              .             CC
;
data want;
 update have(obs=0) have;
 by id;
 output;
 run;
 
 proc print;
 run;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 21 Dec 2019 11:41:03 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-12-21T11:41:03Z</dc:date>
    <item>
      <title>Data restructure in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613384#M179119</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have one query could you please help me on this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input Dataset :-&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Jbcode1 Jbcode2 Jbcode3&lt;/P&gt;&lt;P&gt;101 AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BB&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need output like below&amp;nbsp;&lt;/P&gt;&lt;P&gt;output dataset ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; Jbcode1 Jbcode2 Jbcode3&lt;/P&gt;&lt;P&gt;101&amp;nbsp; AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;101&amp;nbsp; AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BB&lt;/P&gt;&lt;P&gt;101&amp;nbsp; AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Dec 2019 11:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613384#M179119</guid>
      <dc:creator>ganeshsas764</dc:creator>
      <dc:date>2019-12-21T11:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: Data restructure in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613391#M179122</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID (Jbcode1 Jbcode2 Jbcode30) ($);
cards;
101 AA     . .     
101   .          BB .
101   .              .             CC
;
data want;
 update have(obs=0) have;
 by id;
 output;
 run;
 
 proc print;
 run;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Dec 2019 11:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613391#M179122</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-12-21T11:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Data restructure in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613393#M179123</link>
      <description>&lt;P&gt;Thank you very much&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Dec 2019 13:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613393#M179123</guid>
      <dc:creator>ganeshsas764</dc:creator>
      <dc:date>2019-12-21T13:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Data restructure in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613396#M179125</link>
      <description>&lt;P&gt;I have seen people use this type of code on a number of occasions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
update have(obs=0) have;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can someone explain how/why it works?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Dec 2019 15:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613396#M179125</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-21T15:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Data restructure in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613399#M179128</link>
      <description>&lt;P&gt;UPDATE basics:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It takes two data sets.&amp;nbsp; The first is a master data set (meaning no duplicate values for BY values).&amp;nbsp; The second is a set of transactions to apply to the master.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There can be mismatches ... BY values that appear&amp;nbsp; in one data set but not the other.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UPDATE takes all the transactions, and uses the nonmissing values only to replace values in the master data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It outputs just one observation per BY group, once all the transactions have been applied.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UPDATE feature:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can add an OUTPUT statement, since this is part of a DATA step.&amp;nbsp; UPDATE then outputs each observation, instead of waiting until all the transactions have been applied.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Paper presentation at next SGF.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Dec 2019 15:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613399#M179128</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-12-21T15:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: Data restructure in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613400#M179129</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have seen people use this type of code on a number of occasions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
update have(obs=0) have;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can someone explain how/why it works?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The UPDATE statement requires two datasets. The first one is the original source dataset and the second one is the transactions to be applied.&amp;nbsp; In addition the source dataset must have unique observations for the BY variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By using the same dataset for both and use the OBS= dataset option you are starting with a empty source dataset treating all of the data as transactions.&amp;nbsp; So for the first observation in the BY group the values are just copied from the transaction dataset as a new output record.&amp;nbsp; For the 2nd, 3rd, etc observation in the transaction dataset the non-missing values will overwrite the current value and the missing values will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other trick that the usage in this thread added as to include an explicit OUTPUT statement.&amp;nbsp; Without the explicit OUTPUT the UPDATE function will only output the final result of all of the transactions for the by group.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Dec 2019 15:46:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613400#M179129</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-21T15:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: Data restructure in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613401#M179130</link>
      <description>&lt;P&gt;Thanks for the explanations, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Dec 2019 17:22:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613401#M179130</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-21T17:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: Data restructure in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613404#M179132</link>
      <description>&lt;P&gt;Thanks for the explanation &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for supposing id values different if any values are missing particular variable so&amp;nbsp; I need to replace with above non-missing value to below the missing value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:-&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;input :-&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Id&amp;nbsp; &amp;nbsp; JB1&amp;nbsp; &amp;nbsp; JB2&amp;nbsp; JB3&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&amp;nbsp; &amp;nbsp; &amp;nbsp;C&lt;/P&gt;&lt;P&gt;102&amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; D&amp;nbsp; &amp;nbsp; &amp;nbsp; F&lt;/P&gt;&lt;P&gt;103&amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need output like below&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Id&amp;nbsp; &amp;nbsp; JB1&amp;nbsp; &amp;nbsp; JB2&amp;nbsp; JB3&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&amp;nbsp; &amp;nbsp; &amp;nbsp;C&lt;/P&gt;&lt;P&gt;102&amp;nbsp; &amp;nbsp;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;D&amp;nbsp; &amp;nbsp; &amp;nbsp; F&lt;/P&gt;&lt;P&gt;103&amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;D&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;F&lt;/P&gt;</description>
      <pubDate>Sat, 21 Dec 2019 18:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613404#M179132</guid>
      <dc:creator>ganeshsas764</dc:creator>
      <dc:date>2019-12-21T18:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: Data restructure in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613405#M179133</link>
      <description>&lt;P&gt;Is UPDATE a new statement?&lt;/P&gt;</description>
      <pubDate>Sat, 21 Dec 2019 19:26:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613405#M179133</guid>
      <dc:creator>Ubai</dc:creator>
      <dc:date>2019-12-21T19:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: Data restructure in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613406#M179134</link>
      <description>&lt;P&gt;Good afternoon Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; FWIW, I tried to pen the concept though not eloquent and didn't even proof read once, so apologies for the spelling errors and lack of flow having written too fast. Anyways, you can treat it as Garbage in-out &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you have time:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since we know that UPDATE statement typically uses two datasets namely master dataset on the left and transaction dataset on the right to update non missing values from transaction dataset based on the value of the BY group. This essentially means it’s yet another LOOK-UP technique that does an update based on matches.&lt;/P&gt;
&lt;P&gt;As usual BY GROUP values in both datasets requires to be ordered or indexed for Datastep processing though the exception being Modify statement that does not require either of the datasets to be ordered or indexed. This is for the obvious reason that LOOK-UP by means of Modify statement does a rather “dynamic WHERE processing using values of Transaction dataset”. We shall delve into the fun of MODIFY statement some other time in order to not deviate from the scope limiting to just UPDATE statement.&lt;/P&gt;
&lt;P&gt;The functionality of UPDATE statement has similarities with MERGE and MODIFY statement making it a very interesting statement having flavors of both.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;WRT MERGE&lt;/EM&gt;, This perspective of the nomenclature could be called MATCH-UPDATE akin to MATCH-MERGE based on a BY GROUP. &amp;nbsp;&amp;nbsp;In other words, the matches By GROUP values that contribute can be identified using the IN= dataset option that flags the matches and NON-MATCHES.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;WRT MODIFY, &lt;/EM&gt;The functional similarity is that both reads observations from Transaction dataset(2&lt;SUP&gt;nd&lt;/SUP&gt; dataset) and does a LOOK UP with a Master dataset(1&lt;SUP&gt;st&lt;/SUP&gt; dataset). The distinction from merge being a combine not based on position of by group values.&lt;/P&gt;
&lt;P&gt;Rule of Thumb for UPDATE:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Master Dataset (1&lt;SUP&gt;st&lt;/SUP&gt; dataset) cannot have duplicate values of the BY GROUP or in other words must be unique. Hmm, what’s the big deal about this restriction? Well, the matches from the Transaction dataset (2&lt;SUP&gt;nd&lt;/SUP&gt; dataset) updates only the 1&lt;SUP&gt;st&lt;/SUP&gt; value of the BY GROUP. Should 1&lt;SUP&gt;st&lt;/SUP&gt; dataset have multiple values for a BY GROUP, SAS writes a WARNING note to the LOG stating “WARNING: The MASTER data set contains more than one observation for a BY group.”&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL start="2"&gt;
&lt;LI&gt;Transaction dataset (2&lt;SUP&gt;nd&lt;/SUP&gt; dataset) can have more or values of BY GROUP and there is no restriction. If there’s just one, no biggie as the update becomes ONE to ONE update. However, when there are duplicates, there poses a question? I guess this is where pure diligence of business user’s knowledge of data and requirement applies at best. Do we want to update 1&lt;SUP&gt;st&lt;/SUP&gt; records, 2&lt;SUP&gt;nd&lt;/SUP&gt; record or the nth record of the matching By-GROUP from the transaction dataset or all records of the matching by-group?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let’s take a simple example with NON MISSING Values to understand how UPDATE stuff works.&lt;/P&gt;
&lt;P&gt;Dataset ONE has unique ID and Dataset two has multiples.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; one;&lt;/P&gt;
&lt;P&gt;input id v2;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;1 2&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; two;&lt;/P&gt;
&lt;P&gt;input id v2;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;1 4&lt;/P&gt;
&lt;P&gt;1 5&lt;/P&gt;
&lt;P&gt;2 5&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;update one(in=a) two(in=b);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;one=a;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;two=b;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;TABLE&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;TABLE&gt;
&lt;THEAD&gt;
&lt;T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Y&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;What happened is that for ID=1 in one dataset, SAS found a match from two for the BY GROUP value ID= 1.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;So during the 1&lt;SUP&gt;st &lt;/SUP&gt;Datastep iteration, SAS read the 1&lt;SUP&gt;st&lt;/SUP&gt; values from one, found a match in two. In the very same datastep iteration, SAS continues to read all values of matching BY GROUP for ID=1 from dataset two.&lt;/LI&gt;
&lt;LI&gt;So basically, it almost seems like a one to many match occurring within just one datastep iteration where v2=2 in one is replaced by v2=4 from two in the PDV. Then since continues to read from two, v2=4 is replaced by v2=5 in the PDV&lt;/LI&gt;
&lt;LI&gt;The automatic output and return at the end of the datastep that we know writes the values of the PDV to the output buffer and eventually to the output dataset want&lt;/LI&gt;
&lt;LI&gt;In essence, we have done two updates for v2 in ID=1 in one using v2 in two implicitly. Why I call implicit is because of the 2&lt;SUP&gt;nd&lt;/SUP&gt; update v2=5 replacing v2=4 is not explicitly written to the output dataset in the above example.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;So WHAT-IF we want to keep all the records of update occurrences?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;This makes it obvious that we would need the explicit OUTPUT statement in the code. So adding an explicit statement makes sure, all records read sequentially from two into the PDV are written to the output datset WANT.&lt;/P&gt;
&lt;P&gt;/*Adding an output statement*/&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;update one(in=a) two(in=b);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;one=a;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;two=b;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;TABLE&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;v2&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;one&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lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore, it is increasingly clear to discern that how observations read from Transaction dataset (two) update data values matching By-groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In both the above outputs, we could notice that if there is non-matching BY GROUP value in two, the by group gets appended to the output dataset. &amp;nbsp;Or in other words, whenever there is a non-matching By GROUP in transaction (two) dataset, the sequentially read observations read into the PDV is also written to the output dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;So WHAT-IF there happens to be multiple occurrences of nonmatching BY GROUP values in two?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Let’s modify two to include one more record for ID=2 (2 &amp;nbsp;6) below and comprehend what happens during update&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; two;&lt;/P&gt;
&lt;P&gt;input id v2;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;1 4&lt;/P&g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TR&gt;
&lt;TD&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;6&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let’s iterate how stuff works again:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;A match is found for ID=1 from both datasets one and two&lt;/LI&gt;
&lt;LI&gt;Observations from two are read sequentially replacing v2=2 with v2=4 and v2=6 in the PDV.&lt;/LI&gt;
&lt;LI&gt;Since no explicit OUTPUT statement is used, the PDV variable V2 value is over written every time a record is read from two for the BY GROUP.&lt;/LI&gt;
&lt;LI&gt;Finally, The implicit OUTPUT statement writes the record into the output dataset WANT&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Intuitively, including an explicit OUTPUT statement will write each time a record that is read into the PDV from TWO to the output dataset.&lt;/P&gt;
&lt;P&gt;/*Adding an output statement*/&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;update one(in=a) two(in=b);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;one=a;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;two=b;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;TABLE&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&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
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;STRONG&gt;So WHAT-IF there happens to be multiple occurrences of nonmatching BY GROUP values in one and two?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This is where crux of situation or rather the UPDATE statement apexes. We can recall that only the 1&lt;SUP&gt;st&lt;/SUP&gt; observation of the BY GROUP in the master dataset (one) will be updated with values from matching BY GROUP of the transaction dataset (two) and a warning note is written to the LOG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; one;&lt;/P&gt;
&lt;P&gt;input id v2;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;1 2&lt;/P&gt;
&lt;P&gt;1 3&lt;/P&gt;
&lt;P&gt;1 7&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; two;&lt;/P&gt;
&lt;P&gt;input id v2;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;1 4&lt;/P&gt;
&lt;P&gt;1 5&lt;/P&gt;
&lt;P&gt;2 5&lt;/P&gt;
&lt;P&gt;2 6&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;/*Adding an output statement*/&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;update one(in=a) two(in=b);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;one=a;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;two=b;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;*output;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WARNING: The MASTER data set contains more than one observation for a BY group.&lt;/P&gt;
&lt;P&gt;a=1 b=0 id=1 v2=3 FIRST.id=0 LAST.id=0 one=1 two=0 _ERROR_=1 _N_=3&lt;/P&gt;
&lt;P&gt;WARNING: The MASTER data set contains more than one observation for a BY group.&lt;/P&gt;
&lt;P&gt;a=1 b=0 id=1 v2=7 FIRST.id=0 LAST.id=1 one=1 two=0 _ERROR_=1 _N_=4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above elucidation unvaryingly makes us to expect only the record 1 2 would be updated as that is the 1st record of the BY GROUP in one (master dataset). Uncommenting the output statement would of course write all the records read from Transaction dataset (two) to the output dataset want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;MISSING Values Consideration:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The default action for UPDATE statement is to only update master dataset (one) values with non-missing values from the transaction dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppose we have a missing value in 2&lt;SUP&gt;nd&lt;/SUP&gt; dataset. The UPDATEMODE Missingvalue default check prevents the missing value from replacing a non-missing value in a PDV variable when a match Is found or when a match isn’t found is not appended as it would otherwise had the value been non-missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; one;&lt;/P&gt;
&lt;P&gt;input id v2;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;1 2&lt;/P&gt;
&lt;P&gt;1 3&lt;/P&gt;
&lt;P&gt;1 7&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; two;&lt;/P&gt;
&lt;P&gt;input id v2;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;1 4&lt;/P&gt;
&lt;P&gt;1 .&lt;/P&gt;
&lt;P&gt;2 5&lt;/P&gt;
&lt;P&gt;2 6&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;/*Adding an output statement*/&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;update one(in=a) two(in=b);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;one=a;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;two=b;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;*output;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABL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P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;V2=2 is replaced by 4 however v2=4 is &lt;STRONG&gt;&lt;EM&gt;not&lt;/EM&gt;&lt;/STRONG&gt; replaced by the sequential missing value.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;UPDATE &lt;/EM&gt;HAVE&lt;EM&gt; (OBS=0) &lt;/EM&gt;HAVE&lt;EM&gt;;&amp;nbsp; &lt;/EM&gt;&amp;nbsp;seems like LOCF (Last observation carried forward) with an OUTPUT statement or collapsing all records into one complete record with NON-MISSING Values without an OUTPUT statement?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; one;&lt;/P&gt;
&lt;P&gt;input id v2 v3 v4;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;1 . . 4&lt;/P&gt;
&lt;P&gt;1 . 3 .&lt;/P&gt;
&lt;P&gt;1 2 . .&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;An Intuitive thought looking into the dataset based upon what has been expounded so far could be&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;UPDATE &lt;/EM&gt;HAVE&lt;EM&gt; (OBS=0) &lt;/EM&gt;HAVE &lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;No observation is read from the master dataset HAVE&lt;/LI&gt;
&lt;LI&gt;Like a SELF-MERGE/JOIN= that we are used to and are familiar with, HAVE here is used as Transaction dataset&lt;/LI&gt;
&lt;LI&gt;LOOK UP should fail because of OBS=0 used in master&lt;/LI&gt;
&lt;LI&gt;Therefore records read from Transaction for each BY GROUP should append to the new dataset WANT&lt;/LI&gt;
&lt;LI&gt;1&lt;SUP&gt;st&lt;/SUP&gt; record . . 4 is read into the PDV from Trans(one) beginning with the 1&lt;SUP&gt;st&lt;/SUP&gt; by group&lt;/LI&gt;
&lt;LI&gt;With MISSINGVALUE default check in place, 4 is read into the PDV while initial missing values remain as-is&lt;/LI&gt;
&lt;LI&gt;Next record . 3 . is yet again checked for the default MISSINGVALUE and so only 3, replaces the missing value in PDV. 4 remains as-is. Now we have . 3 4 in the PDV.&lt;/LI&gt;
&lt;LI&gt;The next trans record is check for missing and this time, 2 replaces the missing value in PDV resulting with values 2 3 4&lt;/LI&gt;
&lt;LI&gt;The implicit OUTPUT writes the 2 3 4 to the output dataset.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Let’s test:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; one;&lt;/P&gt;
&lt;P&gt;input id v2 v3 v4;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;1 . . 4&lt;/P&gt;
&lt;P&gt;1 . 3 .&lt;/P&gt;
&lt;P&gt;1 2 . .&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;update one(obs=&lt;STRONG&gt;0&lt;/STRONG&gt;) one;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;by id;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;/*Adding an output*/&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;update one(obs=&lt;STRONG&gt;0&lt;/STRONG&gt; in=a) one(in=b);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;one=a;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;two=a;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Now, to make it seem like a LOCF, the obvious would have to be the inclusion of explicit OUTPUT statement i.e. to output every occurrence of read from trans dataset. The only difference it makes here is because the values are missing, the logic works well otherwise, the meaning of UPDATE with real values holds true significance. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Dec 2019 04:43:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613406#M179134</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-22T04:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Data restructure in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613407#M179135</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122086"&gt;@Ubai&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is UPDATE a new statement?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No.&amp;nbsp; I used it in 1983.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Dec 2019 19:50:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-restructure-in-sas/m-p/613407#M179135</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-21T19:50:40Z</dc:date>
    </item>
  </channel>
</rss>

