<?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: Modify, update or other tricks conditionally with two tables and adding observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515980#M139321</link>
    <description>&lt;P&gt;Thank you for all your effort.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will have to look into your solution for a while longer and try to make this work. It will take a while.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;</description>
    <pubDate>Mon, 26 Nov 2018 13:27:10 GMT</pubDate>
    <dc:creator>MsGeritO</dc:creator>
    <dc:date>2018-11-26T13:27:10Z</dc:date>
    <item>
      <title>Modify, update or other tricks conditionally with two tables and adding observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515324#M139013</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to update a dataset. I get the first level of complication done:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input id concern$ morestuff$;&lt;BR /&gt;datalines;&lt;BR /&gt;1 . whatever&lt;BR /&gt;1 . other&lt;BR /&gt;2 . whatever&lt;BR /&gt;2 . other&lt;BR /&gt;3 code whatever&lt;BR /&gt;3 code other&lt;BR /&gt;4 code whatever&lt;BR /&gt;4 code other&lt;BR /&gt;5 code whatever&lt;BR /&gt;6 . whatever&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data transaction;&lt;BR /&gt;input id concern$;&lt;BR /&gt;datalines;&lt;BR /&gt;1 .&lt;BR /&gt;2 tx&lt;BR /&gt;3 .&lt;BR /&gt;4 tx&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want; set have;&lt;/P&gt;&lt;P&gt;run; *Just to keep "have" and "want" separate;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; update want master&lt;BR /&gt;set concern=(select concern from transaction trans&lt;BR /&gt;where master.id=trans.id)&lt;BR /&gt;where master.concern = "."; *As "code" can be any of 6,730 options;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Now I need to add further complications: ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data transaction2;&lt;BR /&gt;input id concern$ ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 .&lt;BR /&gt;1 .&lt;BR /&gt;2 tx&lt;BR /&gt;2 txt&lt;BR /&gt;3 .&lt;BR /&gt;4 tx&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* "tx" or "txt" could be anything alphanumeric, number of options are hard to count;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data otherwant;&lt;BR /&gt;input id concern$ morestuff$;&lt;BR /&gt;datalines;&lt;BR /&gt;1 . whatever&lt;BR /&gt;1 . other&lt;BR /&gt;2 tx whatever&lt;BR /&gt;2 tx other&lt;BR /&gt;2 txt whatever&lt;BR /&gt;2 txt other&lt;BR /&gt;3 code whatever&lt;BR /&gt;3 code other&lt;BR /&gt;4 code whatever&lt;BR /&gt;4 code other&lt;BR /&gt;4 tx whatever&lt;BR /&gt;4 tx other&lt;BR /&gt;5 code whatever&lt;BR /&gt;6 . whatever&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And this is the point where I am stuck. I have tried some options, but none gave the right solution. As far as I can tell we are using SAS 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope somebody can help me out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anything is appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Gerit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 11:47:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515324#M139013</guid>
      <dc:creator>MsGeritO</dc:creator>
      <dc:date>2018-11-22T11:47:51Z</dc:date>
    </item>
    <item>
      <title>Re: Modify, update or other tricks conditionally with two tables and adding observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515325#M139014</link>
      <description>&lt;P&gt;Looks like a simple full join to me.&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table want as
  select coalsece(a.id,b.id) as id,
         a.morestuff,
         b.concern
  from   have a
  full join transaction b
  on     a.id=b.id;
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Nov 2018 11:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515325#M139014</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-22T11:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: Modify, update or other tricks conditionally with two tables and adding observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515335#M139018</link>
      <description>&lt;P&gt;Thank you. However, this overwrites "code" in all cases which I need to remain.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 12:41:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515335#M139018</guid>
      <dc:creator>MsGeritO</dc:creator>
      <dc:date>2018-11-22T12:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: Modify, update or other tricks conditionally with two tables and adding observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515342#M139024</link>
      <description>&lt;PRE&gt;proc sql;
  create table want as
  select coalsece(a.id,b.id) as id,
         a.morestuff,
         coalesce(a.concern,b.concern) as concern
  from   have a
  full join transaction b
  on     a.id=b.id;
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Nov 2018 13:05:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515342#M139024</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-22T13:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: Modify, update or other tricks conditionally with two tables and adding observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515351#M139028</link>
      <description>&lt;P&gt;With this solution I am still missing the resulting observations&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;2 txt whatever&lt;BR /&gt;2 txt other&lt;BR /&gt;...&lt;BR /&gt;4 tx whatever&lt;BR /&gt;4 tx other&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Whereas I need to keep all the observations which your latest code produced.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 13:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515351#M139028</guid>
      <dc:creator>MsGeritO</dc:creator>
      <dc:date>2018-11-22T13:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: Modify, update or other tricks conditionally with two tables and adding observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515353#M139029</link>
      <description>&lt;P&gt;You will need to be clearer on what issues are.&amp;nbsp; I cannot guess.&amp;nbsp; I run this code, and it looks fine:&lt;/P&gt;
&lt;PRE&gt;data otherwant;
input id concern$ morestuff$;
datalines;
1 . whatever
1 . other
2 tx whatever
2 tx other
2 txt whatever
2 txt other
3 code whatever
3 code other
4 code whatever
4 code other
4 tx whatever
4 tx other
5 code whatever
6 . whatever
;
run;
data have;
input id concern$ morestuff$;
datalines;
1 . whatever
1 . other
2 . whatever
2 . other
3 code whatever
3 code other
4 code whatever
4 code other
5 code whatever
6 . whatever
;
run;
proc sql;
  create table want as
  select coalesce(a.id,b.id) as id,
         a.morestuff,
         coalesce(a.concern,b.concern) as concern
  from   have a
  full join otherwant b
  on     a.id=b.id;
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Nov 2018 13:48:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515353#M139029</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-22T13:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: Modify, update or other tricks conditionally with two tables and adding observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515355#M139030</link>
      <description>&lt;P&gt;Dataset "otherwant" is the wanted other result. I need to acchieve it from the datasets "have" and "transaction2".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am very sorry about the confusion.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 14:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515355#M139030</guid>
      <dc:creator>MsGeritO</dc:creator>
      <dc:date>2018-11-22T14:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: Modify, update or other tricks conditionally with two tables and adding observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515362#M139033</link>
      <description>&lt;P&gt;Am afraid your data is to blame here.&amp;nbsp; Merging will only bring in at maximum, the product of the two available, i.e. the total obs.&amp;nbsp; You want more records on that based on number of observations in one of the dataset - but only in some instances.&amp;nbsp; Therefore you manually need to code this in, something like:&lt;/P&gt;
&lt;PRE&gt;proc transpose data=have out=inter;
  by id;
  var concern;
  id morestuff;
run;

data inter;
  merge inter transaction (rename=(concern=c));
  by id;
  if whatever="" and other="" then do;
    concern=c;
    output;
    concern=c;
    output;
  end;
  else if whatever ne "" and other ne "" then do;
    concern=whatever;
    output;
    concern=other;
    output;
  ...
  
run;&lt;/PRE&gt;
&lt;P&gt;I would really advise to look at the whole process and see if you can alter it, or provide more accurate test samples so we can see what it is you really want to do, and what you have.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 14:29:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515362#M139033</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-22T14:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: Modify, update or other tricks conditionally with two tables and adding observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515980#M139321</link>
      <description>&lt;P&gt;Thank you for all your effort.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will have to look into your solution for a while longer and try to make this work. It will take a while.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Nov 2018 13:27:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/515980#M139321</guid>
      <dc:creator>MsGeritO</dc:creator>
      <dc:date>2018-11-26T13:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Modify, update or other tricks conditionally with two tables and adding observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/516662#M139571</link>
      <description>&lt;P&gt;I think I found a solution. I couldn't solve it in one step. Maybe there is a better way to solve it, but this gives the correct result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;* 1. Create data set with no missing "concern";&lt;BR /&gt;data trans2; set transaction2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if concern ^= "";&lt;BR /&gt;run;&lt;BR /&gt;* 2. Check if "concern" is in "have2" as well as "trans2".;&lt;BR /&gt;data have2; set want;&lt;BR /&gt;&amp;nbsp; newid = strip(id)||"."||strip(concern);&lt;BR /&gt;run;&lt;BR /&gt;data trans2; set trans2;&lt;BR /&gt;&amp;nbsp; newid = strip(id)||"."||strip(concern);&lt;BR /&gt;run;&lt;BR /&gt;* Those in trans2 with no entry in have2 will have empty&lt;BR /&gt;&amp;nbsp; cells for variable "morestuff";&lt;BR /&gt;proc sql;&lt;BR /&gt;&amp;nbsp; create table test6 as&lt;BR /&gt;&amp;nbsp; select coalesce(a.id,b.id) as id,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.*,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; b.morestuff&lt;BR /&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp; trans2 a left join have2 b&lt;BR /&gt;&amp;nbsp;&amp;nbsp; on&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (a.newid eq b.newid);&lt;BR /&gt;quit;&lt;BR /&gt;* Keep only those of test6 (origin: trans2)&lt;BR /&gt;&amp;nbsp; which have no entry in "morestuff", i.e.&lt;BR /&gt;&amp;nbsp; those which are not (yet) in have2, but&lt;BR /&gt;&amp;nbsp; with more information in trans2;&lt;BR /&gt;data interim; set test6;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; keep id newid positive;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if morestuff = "" then positive = 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if positive = 1;&lt;BR /&gt;run;&lt;BR /&gt;* Transfer knowledge that there is more information&lt;BR /&gt;&amp;nbsp; in trans2 for specific observations in have2 to have2;&lt;BR /&gt;data have2; merge have2 interim;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; drop newid;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; by id;&lt;BR /&gt;run;&lt;BR /&gt;* Single out those observations which have more information&lt;BR /&gt;&amp;nbsp; in trans2. Keep those variables which need to be concottonated&lt;BR /&gt;&amp;nbsp; to information in trans2. Here only "morestuff".;&lt;BR /&gt;data morestuff; set have2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; keep id morestuff;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if positive = 1;&lt;BR /&gt;run;&lt;BR /&gt;* Just in case that there can be duplicates;&lt;BR /&gt;proc sort data=morestuff;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; by id morestuff;&lt;BR /&gt;run;&lt;BR /&gt;data shortmorestuff; set morestuff;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; by id morestuff;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if first.morestuff then output;&lt;BR /&gt;run;&lt;BR /&gt;* Add all relevant information from shortmorestuff to&lt;BR /&gt;&amp;nbsp; test6 (origin: trans2, but only relevant observations);&lt;BR /&gt;* First: Create data set similar to interim, but with&lt;BR /&gt;&amp;nbsp; relevant information;&lt;BR /&gt;data relevant; set test6;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; keep id concern ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if morestuff = "";&lt;BR /&gt;run;&lt;BR /&gt;* Second: Bring together;&lt;BR /&gt;proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; create table transwithadded as&lt;BR /&gt;&amp;nbsp;&amp;nbsp; select coalesce(a.id, b.id) as id, a.*, b.*&lt;BR /&gt;&amp;nbsp;&amp;nbsp; from relevant a natural full join shortmorestuff b&lt;BR /&gt;&amp;nbsp;&amp;nbsp; ;&lt;BR /&gt;* Attach transwithadded to have2;&lt;BR /&gt;data result; set have2 transwithadded;&lt;BR /&gt;&amp;nbsp;drop positive ;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 13:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/516662#M139571</guid>
      <dc:creator>MsGeritO</dc:creator>
      <dc:date>2018-11-28T13:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Modify, update or other tricks conditionally with two tables and adding observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/516669#M139576</link>
      <description>&lt;P&gt;Well, if it works all the better&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&amp;nbsp; There are always "better" ways, but working code is better than possibility.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 14:11:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Modify-update-or-other-tricks-conditionally-with-two-tables-and/m-p/516669#M139576</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-28T14:11:02Z</dc:date>
    </item>
  </channel>
</rss>

