<?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: Insert data from a bigger dataset into a smaller dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Insert-data-from-a-bigger-dataset-into-a-smaller-dataset/m-p/702642#M215216</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, I produced B from A using a matching code, matching cases and controls. However, Dataset A got the values (no/yes) of 4 numeric variables changed. That means that 4 columns received new values in dataset A.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to implement these changes that were made in Dataset A into Dataset B. I cannot simply run another matching procedure with Dataset A because I am already using the results of all other variables from Dataset B. And Matching would create another random dataset. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;B is just a subset of observations in A.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Nov 2020 21:13:10 GMT</pubDate>
    <dc:creator>firesantos</dc:creator>
    <dc:date>2020-11-30T21:13:10Z</dc:date>
    <item>
      <title>Insert data from a bigger dataset into a smaller dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-data-from-a-bigger-dataset-into-a-smaller-dataset/m-p/702617#M215201</link>
      <description>&lt;P&gt;I have a bigger dataset (Dataset A) that I used to generate a smaller dataset (Dataset B).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It turns out that 4 numeric variables from Dataset A were updated (Dataset C). Now I need to update these variables in dataset B too. Dataset A and B have in common ID numbers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please help me find a code to run this update?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can name:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset A: datasetA&lt;/P&gt;&lt;P&gt;Dataset C: datasetC&lt;/P&gt;&lt;P&gt;ID numbers: IDnum&lt;/P&gt;&lt;P&gt;Variables that need to be updated: Var1 Var 2 Var 3 Var4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jose Diego.&amp;nbsp;&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 19:44:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-data-from-a-bigger-dataset-into-a-smaller-dataset/m-p/702617#M215201</guid>
      <dc:creator>firesantos</dc:creator>
      <dc:date>2020-11-30T19:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: Insert data from a bigger dataset into a smaller dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-data-from-a-bigger-dataset-into-a-smaller-dataset/m-p/702622#M215202</link>
      <description>&lt;P&gt;One method: a hash object:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds_d;
set ds_b;
if _n_ = 1
then do;
  declare hash c (dataset:"ds_c (keep=id_num var1 var2 var3 var4)");
  c.definekey("id_num");
  c.definedata("var1","var2","var3","var4");
  c.definedone();
end;
rc = c.find();
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If both datasets are already sorted by id_num, a data step MERGE will probably be most efficient.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 20:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-data-from-a-bigger-dataset-into-a-smaller-dataset/m-p/702622#M215202</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-30T20:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: Insert data from a bigger dataset into a smaller dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-data-from-a-bigger-dataset-into-a-smaller-dataset/m-p/702630#M215207</link>
      <description>&lt;P&gt;I don't understand what you are asking.&amp;nbsp; It might not even be possible depending on what is actually going on.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sounds like you ran some program to produce B from A. Then you got a new dataset C that you used to update A.&amp;nbsp; It is not clear how C updates A.&amp;nbsp; Also it is not sure if you updated the dataset A in place or if you used C and A to produce a new dataset, say A_prime.&amp;nbsp; And now you want to know if there is some way to use C to update B.&amp;nbsp; Do you want to update B in place or use B and C to B_prime?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would seem to me that whether you can use C to update B depends on how B was made from A.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is B just a subset of the observations in A?&amp;nbsp; If so then it might be possible.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If B was produced from A via a more complex algorithm than you probably cannot just use C to update B.&amp;nbsp; You will need to recreate B from the updated A (or create B_prime from A_prime).&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 20:38:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-data-from-a-bigger-dataset-into-a-smaller-dataset/m-p/702630#M215207</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-30T20:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: Insert data from a bigger dataset into a smaller dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-data-from-a-bigger-dataset-into-a-smaller-dataset/m-p/702631#M215208</link>
      <description>&lt;P&gt;Dear Kurt,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your answer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry but could you please clarify what do you mean by&amp;nbsp;&lt;/P&gt;&lt;P&gt;if _n_=1 ?&lt;/P&gt;&lt;P&gt;Also, what is this declare hash (dataset:&lt;/P&gt;&lt;P&gt;Also, what is this rc=c.find.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, the datasets are indeed sorted by ID numbers. However, they have &amp;nbsp;different population sizes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am sorry for my ignorance...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 21:14:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-data-from-a-bigger-dataset-into-a-smaller-dataset/m-p/702631#M215208</guid>
      <dc:creator>firesantos</dc:creator>
      <dc:date>2020-11-30T21:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Insert data from a bigger dataset into a smaller dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-data-from-a-bigger-dataset-into-a-smaller-dataset/m-p/702642#M215216</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, I produced B from A using a matching code, matching cases and controls. However, Dataset A got the values (no/yes) of 4 numeric variables changed. That means that 4 columns received new values in dataset A.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to implement these changes that were made in Dataset A into Dataset B. I cannot simply run another matching procedure with Dataset A because I am already using the results of all other variables from Dataset B. And Matching would create another random dataset. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;B is just a subset of observations in A.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 21:13:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-data-from-a-bigger-dataset-into-a-smaller-dataset/m-p/702642#M215216</guid>
      <dc:creator>firesantos</dc:creator>
      <dc:date>2020-11-30T21:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Insert data from a bigger dataset into a smaller dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-data-from-a-bigger-dataset-into-a-smaller-dataset/m-p/702649#M215218</link>
      <description>&lt;P&gt;The documentation of SAS Component Objects is found &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lecompobjref&amp;amp;docsetTarget=part-2.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;The MERGE solution looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds_d;
merge
  ds_b (in=b)
  ds_c (keep=id_num var1 var2 var3 var4)
;
by id_num;
if b;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Only observations already present in ds_b will be kept, and the variables read from ds_c will overwrite those read from ds_b.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 21:35:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-data-from-a-bigger-dataset-into-a-smaller-dataset/m-p/702649#M215218</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-30T21:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: Insert data from a bigger dataset into a smaller dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-data-from-a-bigger-dataset-into-a-smaller-dataset/m-p/702655#M215220</link>
      <description>&lt;P&gt;So if C has just the five variables, ID and VAR1-VAR4 then a simple MERGE will do the trick.&lt;/P&gt;
&lt;P&gt;You can use the IN= dataset option to make a variable you can use to make sure that merging in C does not add observations.&amp;nbsp; In case C has other variables you don't want you can use the KEEP= dataset option to only keep the variables you want.&amp;nbsp; Note this assumes that ID is unique identifier in both datasets. That is for any value of ID there is at most one observation in B and at most one observation in C that has that value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new_b ;
  merge b(in=inb) c (keep=id var1-var4);
  by id;
  if inb;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 22:14:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-data-from-a-bigger-dataset-into-a-smaller-dataset/m-p/702655#M215220</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-30T22:14:12Z</dc:date>
    </item>
  </channel>
</rss>

