<?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: How to keep required OBS while merging datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-required-OBS-while-merging-datasets/m-p/337678#M76726</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/68272"&gt;@knveraraju91&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to merge dataset one and fail to get dataset three. With my code I am getting only id =2 &amp;nbsp;and 4 in the dataset three.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But some these subjects have been screened with different subject number(preid). I need to exclude if both id and preid have sf='Y'.&lt;/P&gt;
&lt;P&gt;if preid has sf='N' and id has sf='Y' then id=preid and output to dataset three.&lt;/P&gt;
&lt;P&gt;Please help.Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data one;&lt;BR /&gt;input id term $ preid;&lt;BR /&gt;datalines;&lt;BR /&gt;1 a 11&lt;BR /&gt;2 b 22&lt;BR /&gt;3 c 33&lt;/P&gt;
&lt;P&gt;4 d&lt;BR /&gt;;&lt;BR /&gt;data fail;&lt;BR /&gt;input id sf$ ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 Y&lt;BR /&gt;2 N&lt;BR /&gt;3 Y&lt;/P&gt;
&lt;P&gt;4 N&lt;BR /&gt;11 N&lt;BR /&gt;22 N&lt;BR /&gt;33 Y&lt;BR /&gt;;&lt;BR /&gt;data three;&lt;BR /&gt;merge one(in=a) fail(in=b);&lt;BR /&gt;by id;&lt;BR /&gt;if a;&lt;BR /&gt;&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;if SF='Y' then delete;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my ouput dataset I&lt;FONT color="#008000"&gt;&lt;STRONG&gt; need all subject with sf='Y'&lt;/STRONG&gt;&lt;/FONT&gt;.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note that your code I highlighted in red says to Delete when the value is the one you want.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Mar 2017 00:15:52 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-03-03T00:15:52Z</dc:date>
    <item>
      <title>How to keep required OBS while merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-required-OBS-while-merging-datasets/m-p/337640#M76699</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to merge dataset one and fail to get dataset three. With my code I am getting only id =2 &amp;nbsp;and 4 in the dataset three.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But some these subjects have been screened with different subject number(preid). I need to exclude if both id and preid have sf='Y'.&lt;/P&gt;&lt;P&gt;if preid has sf='N' and id has sf='Y' then id=preid and output to dataset three.&lt;/P&gt;&lt;P&gt;Please help.Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;input id term $ preid;&lt;BR /&gt;datalines;&lt;BR /&gt;1 a 11&lt;BR /&gt;2 b 22&lt;BR /&gt;3 c 33&lt;/P&gt;&lt;P&gt;4 d&lt;BR /&gt;;&lt;BR /&gt;data fail;&lt;BR /&gt;input id sf$ ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 Y&lt;BR /&gt;2 N&lt;BR /&gt;3 Y&lt;/P&gt;&lt;P&gt;4 N&lt;BR /&gt;11 N&lt;BR /&gt;22 N&lt;BR /&gt;33 Y&lt;BR /&gt;;&lt;BR /&gt;data three;&lt;BR /&gt;merge one(in=a) fail(in=b);&lt;BR /&gt;by id;&lt;BR /&gt;if a;&lt;BR /&gt;if SF='Y' then delete;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my ouput dataset I need all subject with sf='Y'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output needed;&lt;/P&gt;&lt;P&gt;id &amp;nbsp;term&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; b&lt;/P&gt;&lt;P&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp;d&lt;/P&gt;&lt;P&gt;11 &amp;nbsp; &amp;nbsp;a&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output getting:&lt;/P&gt;&lt;P&gt;id &amp;nbsp; term&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; b&lt;/P&gt;&lt;P&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp;d&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 22:29:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-required-OBS-while-merging-datasets/m-p/337640#M76699</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2017-03-02T22:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep required OBS while merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-required-OBS-while-merging-datasets/m-p/337648#M76706</link>
      <description>&lt;P&gt;Sounds like you want something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data three;
  merge one(in=a) fail(in=b);
  by id;
  if a;
run;

proc sort data=three;
  by preid;
run;

data three;
  merge three(in=a) fail (rename=(id=preid sf=sf2) in=b);
  by preid;
  if a;
  if sf eq 'Y' and sf2 eq 'N' then id=preid;
  if not (sf eq 'Y' and sf2 eq 'Y');
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 22:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-required-OBS-while-merging-datasets/m-p/337648#M76706</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-02T22:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep required OBS while merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-required-OBS-while-merging-datasets/m-p/337677#M76725</link>
      <description>&lt;P&gt;You could make a dataset, call it EXCLUDES, consisting of all the ID/PREID pairs that have double SF='Y':&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; create table excludes&lt;/P&gt;
&lt;P&gt;&amp;nbsp; as select a.id, b.id as preid&lt;/P&gt;
&lt;P&gt;&amp;nbsp; from fail as a&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; full join&amp;nbsp;&amp;nbsp; fail a b&lt;/P&gt;
&lt;P&gt;&amp;nbsp; on a.sf=b.sf&lt;/P&gt;
&lt;P&gt;&amp;nbsp; where a.sf='Y' and a.id&amp;lt;b.id&lt;/P&gt;
&lt;P&gt;&amp;nbsp; order by a.id,b.id;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then just merge it with dataset ONE and eliminate all obs from ONE that are also found in EXCLUDES:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=one;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by id preid;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data three;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; merge one&amp;nbsp;&amp;nbsp; excludes (in=inex);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by id preid;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;if inex=0;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code has the advantage, IMO, that it&amp;nbsp;makes the purpose of the program more self-evident.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 00:12:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-required-OBS-while-merging-datasets/m-p/337677#M76725</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-03-03T00:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep required OBS while merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-required-OBS-while-merging-datasets/m-p/337678#M76726</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/68272"&gt;@knveraraju91&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to merge dataset one and fail to get dataset three. With my code I am getting only id =2 &amp;nbsp;and 4 in the dataset three.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But some these subjects have been screened with different subject number(preid). I need to exclude if both id and preid have sf='Y'.&lt;/P&gt;
&lt;P&gt;if preid has sf='N' and id has sf='Y' then id=preid and output to dataset three.&lt;/P&gt;
&lt;P&gt;Please help.Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data one;&lt;BR /&gt;input id term $ preid;&lt;BR /&gt;datalines;&lt;BR /&gt;1 a 11&lt;BR /&gt;2 b 22&lt;BR /&gt;3 c 33&lt;/P&gt;
&lt;P&gt;4 d&lt;BR /&gt;;&lt;BR /&gt;data fail;&lt;BR /&gt;input id sf$ ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 Y&lt;BR /&gt;2 N&lt;BR /&gt;3 Y&lt;/P&gt;
&lt;P&gt;4 N&lt;BR /&gt;11 N&lt;BR /&gt;22 N&lt;BR /&gt;33 Y&lt;BR /&gt;;&lt;BR /&gt;data three;&lt;BR /&gt;merge one(in=a) fail(in=b);&lt;BR /&gt;by id;&lt;BR /&gt;if a;&lt;BR /&gt;&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;if SF='Y' then delete;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my ouput dataset I&lt;FONT color="#008000"&gt;&lt;STRONG&gt; need all subject with sf='Y'&lt;/STRONG&gt;&lt;/FONT&gt;.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note that your code I highlighted in red says to Delete when the value is the one you want.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 00:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-required-OBS-while-merging-datasets/m-p/337678#M76726</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-03T00:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep required OBS while merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-required-OBS-while-merging-datasets/m-p/337683#M76728</link>
      <description>&lt;P&gt;Sorry. That statement should be&amp;nbsp;&lt;SPAN&gt;In my ouput dataset I&lt;/SPAN&gt;&lt;FONT color="#008000"&gt;&lt;STRONG&gt; need all subject with sf='N'&lt;/STRONG&gt;&lt;/FONT&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 01:01:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-required-OBS-while-merging-datasets/m-p/337683#M76728</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2017-03-03T01:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep required OBS while merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-required-OBS-while-merging-datasets/m-p/337966#M76836</link>
      <description>&lt;P&gt;Subsetting if:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;if sf='N';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;keeps on those records where the IF statement is true. Note that the location of the IF statement in your code can be very important if you manipulate any of the variables used. If you might have lower case n and what to keep those either upcase the variable earlier in the code or in the comparison:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;if upcase(sf)='N';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;also if the SF variable might acquire or have leading blanks then you want to strip them as " N" is not equal to "N"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;if upcase(strip(sf)) = 'N';&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 19:11:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-required-OBS-while-merging-datasets/m-p/337966#M76836</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-03T19:11:57Z</dc:date>
    </item>
  </channel>
</rss>

