<?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 Obtain consistent outputs for unique records in a dataset in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Obtain-consistent-outputs-for-unique-records-in-a-dataset/m-p/676633#M36724</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a dataset which contains unique records based on a client id. For example:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Client ID&lt;/TD&gt;&lt;TD&gt;Location&lt;/TD&gt;&lt;TD&gt;Employment Status&lt;/TD&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Metro&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Unemployed&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;2001&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Remote&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Employed&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;2002&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Metro&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Employed&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;2003&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Metro&lt;/TD&gt;&lt;TD&gt;Employed&lt;/TD&gt;&lt;TD&gt;2003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Metro&lt;/TD&gt;&lt;TD&gt;Employed&lt;/TD&gt;&lt;TD&gt;2003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Remote&lt;/TD&gt;&lt;TD&gt;Employed&lt;/TD&gt;&lt;TD&gt;2003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Remote&lt;/TD&gt;&lt;TD&gt;Employed&lt;/TD&gt;&lt;TD&gt;2003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Remote&lt;/TD&gt;&lt;TD&gt;Employed&lt;/TD&gt;&lt;TD&gt;2003&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;Now,using client id = 1 as the example, it shows a discrepancy in the outputs for Location and Employment Status. What I am trying to achieve is a consistent output for these variables based on some conditions. The first condition would be that the client id has to be consistent (i.e. so that it is only looking at records that contain that particular client id. The second condition would be simply be "if any of the outcomes for Location = Remote, then all outcomes for this particular client id would = remote (i.e. the 2 outcomes that = "metro" would be overwritten with "remote".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second condition is not the problem I am having, it is the first condition whereby the "if else statement" that I will use for the second condition needs to be based on the the client id being the same in all records that are to be used to execute this calculation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have searched the forums but am unable to find what I am looking for.&lt;/P&gt;&lt;P&gt;I am a new user so hopefully I have explained myself well enough?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;Cam&lt;/P&gt;</description>
    <pubDate>Fri, 14 Aug 2020 04:24:00 GMT</pubDate>
    <dc:creator>cammmbo70</dc:creator>
    <dc:date>2020-08-14T04:24:00Z</dc:date>
    <item>
      <title>Obtain consistent outputs for unique records in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Obtain-consistent-outputs-for-unique-records-in-a-dataset/m-p/676633#M36724</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a dataset which contains unique records based on a client id. For example:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Client ID&lt;/TD&gt;&lt;TD&gt;Location&lt;/TD&gt;&lt;TD&gt;Employment Status&lt;/TD&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Metro&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Unemployed&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;2001&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Remote&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Employed&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;2002&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Metro&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Employed&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;2003&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Metro&lt;/TD&gt;&lt;TD&gt;Employed&lt;/TD&gt;&lt;TD&gt;2003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Metro&lt;/TD&gt;&lt;TD&gt;Employed&lt;/TD&gt;&lt;TD&gt;2003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Remote&lt;/TD&gt;&lt;TD&gt;Employed&lt;/TD&gt;&lt;TD&gt;2003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Remote&lt;/TD&gt;&lt;TD&gt;Employed&lt;/TD&gt;&lt;TD&gt;2003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Remote&lt;/TD&gt;&lt;TD&gt;Employed&lt;/TD&gt;&lt;TD&gt;2003&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;Now,using client id = 1 as the example, it shows a discrepancy in the outputs for Location and Employment Status. What I am trying to achieve is a consistent output for these variables based on some conditions. The first condition would be that the client id has to be consistent (i.e. so that it is only looking at records that contain that particular client id. The second condition would be simply be "if any of the outcomes for Location = Remote, then all outcomes for this particular client id would = remote (i.e. the 2 outcomes that = "metro" would be overwritten with "remote".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second condition is not the problem I am having, it is the first condition whereby the "if else statement" that I will use for the second condition needs to be based on the the client id being the same in all records that are to be used to execute this calculation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have searched the forums but am unable to find what I am looking for.&lt;/P&gt;&lt;P&gt;I am a new user so hopefully I have explained myself well enough?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;Cam&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2020 04:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Obtain-consistent-outputs-for-unique-records-in-a-dataset/m-p/676633#M36724</guid>
      <dc:creator>cammmbo70</dc:creator>
      <dc:date>2020-08-14T04:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain consistent outputs for unique records in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Obtain-consistent-outputs-for-unique-records-in-a-dataset/m-p/676634#M36725</link>
      <description>&lt;P&gt;You will have to process the dataset twice: in the first round checking if any Location = "Metro" and in the second round adapting Location if necessary. The first condition is achieved by using by-group-processing with first/last - you will find numerous documents explaining anything relevant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is one solution, all in one datastep using two DOW-Loops:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   length FixLocation $ 15;
   FixLocation = " ";
   
   do _n_ = 1 by 1 until(last.ClientId);
      set work.have;
      by ClientId;
      
      if Location = "Metro" then do;
         FixLocation = "Metro";
      end;
   end;
   
   do _n_ = 1 by 1 until(last.ClientId);
      set work.have;
      by ClientId;
      
      if not missing(FixLocation) then do;
         Location = FixLocation;
      end;
      
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Aug 2020 05:04:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Obtain-consistent-outputs-for-unique-records-in-a-dataset/m-p/676634#M36725</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-14T05:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain consistent outputs for unique records in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Obtain-consistent-outputs-for-unique-records-in-a-dataset/m-p/676635#M36726</link>
      <description>&lt;P&gt;Or you could merge the dataset with itself:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_merge;
   merge have have(keep= ClientId Location where=(Location="Metro"));
   by ClientId;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Aug 2020 05:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Obtain-consistent-outputs-for-unique-records-in-a-dataset/m-p/676635#M36726</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-14T05:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain consistent outputs for unique records in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Obtain-consistent-outputs-for-unique-records-in-a-dataset/m-p/676637#M36727</link>
      <description>&lt;P&gt;You don't need an IF .. THEN to do this.&amp;nbsp; A merge of the dataset with a subset of itself (subset where location='Remote') would work, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id location :$6.  emp_status :$12.  year;
datalines;
1	Metro	Unemployed	2001
1	Remote	Employed	2002
1	Metro	Employed	2003
2	Metro	Employed	2003
2	Metro	Employed	2003
3	Remote	Employed	2003
3	Remote	Employed	2003
3	Remote	Employed	2003
run;

data want (drop=_:);
  merge have 
        have (rename=(location=_loc) where=(_loc='Remote') keep=id location);
  by id;
  location=coalescec(_loc,location);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is a merge of have with a subset of itself.&amp;nbsp; If I did not apply the rename (to the 'Remote' subset), then the subset location value would not apply to the latter records within those id's that have more total records than "Remote" records.&amp;nbsp; So a rename of location to _loc is used.&amp;nbsp; Since _LOC is not in the complete set, it is NOT replaced by new incoming values.&amp;nbsp; So any instance of _LOC in an id group will be avaliable for all records in the group.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2020 05:33:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Obtain-consistent-outputs-for-unique-records-in-a-dataset/m-p/676637#M36727</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-08-14T05:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain consistent outputs for unique records in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Obtain-consistent-outputs-for-unique-records-in-a-dataset/m-p/676649#M36729</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks very much for this help Andreas, and thanks Mkeintz for your suggestion. I have used Andreas's first code and this seems to work. I will also try the merge code both of you have supplied and if that also works for me I'll also click that these are also an accepted solution to my problem. Many thanks for your help&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;, it's very much appreciated!!!&lt;/P&gt;&lt;P&gt;Cammbo70&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2020 07:11:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Obtain-consistent-outputs-for-unique-records-in-a-dataset/m-p/676649#M36729</guid>
      <dc:creator>cammmbo70</dc:creator>
      <dc:date>2020-08-14T07:11:50Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain consistent outputs for unique records in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Obtain-consistent-outputs-for-unique-records-in-a-dataset/m-p/677660#M36790</link>
      <description>&lt;P&gt;Hi again&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475" target="_blank" rel="noopener"&gt;&lt;SPAN style="font-family: 'inherit',serif; background: white;"&gt;@andreas_lds&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;One issue I am having with this code is the fix location variable is only generating for the record in which the location was "Metro".&amp;nbsp; All other records for the client id in question are null values.For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Client ID&lt;/TD&gt;&lt;TD&gt;Location&lt;/TD&gt;&lt;TD&gt;Employment Status&lt;/TD&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;TD&gt;FixLocation&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Metro&lt;/TD&gt;&lt;TD&gt;Unemployed&lt;/TD&gt;&lt;TD&gt;2001&lt;/TD&gt;&lt;TD&gt;Metro&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Remote&lt;/TD&gt;&lt;TD&gt;Employed&lt;/TD&gt;&lt;TD&gt;2002&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;no value&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Metro&lt;/TD&gt;&lt;TD&gt;Employed&lt;/TD&gt;&lt;TD&gt;2003&lt;/TD&gt;&lt;TD&gt;Metro&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way in which you can aggregate the "Metro" outcome so that the FixLocation variable generates "Metro" for all records with that Client ID? e.g:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Client ID&lt;/TD&gt;&lt;TD&gt;Location&lt;/TD&gt;&lt;TD&gt;Employment Status&lt;/TD&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;TD&gt;FixLocation&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Metro&lt;/TD&gt;&lt;TD&gt;Unemployed&lt;/TD&gt;&lt;TD&gt;2001&lt;/TD&gt;&lt;TD&gt;Metro&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Remote&lt;/TD&gt;&lt;TD&gt;Employed&lt;/TD&gt;&lt;TD&gt;2002&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Metro&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Metro&lt;/TD&gt;&lt;TD&gt;Employed&lt;/TD&gt;&lt;TD&gt;2003&lt;/TD&gt;&lt;TD&gt;Metro&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Cam&lt;/P&gt;&lt;P&gt;p.s.&amp;nbsp;&lt;SPAN style="font-family: 'inherit',serif; background: white;"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475" target="_blank" rel="noopener"&gt;@andreas_lds&lt;/A&gt;&amp;nbsp;I have attempted a number of different options to do this (e.g. concatenating variables, else if statements) but due to my lack of experience with SAS it was unsuccessful and not worth outlining here what I have attempted.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Aug 2020 23:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Obtain-consistent-outputs-for-unique-records-in-a-dataset/m-p/677660#M36790</guid>
      <dc:creator>cammmbo70</dc:creator>
      <dc:date>2020-08-18T23:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain consistent outputs for unique records in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Obtain-consistent-outputs-for-unique-records-in-a-dataset/m-p/677777#M36791</link>
      <description>&lt;P&gt;Please post the code you have used. The code in the solution changes Location to "Metro" in the second observation.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2020 12:40:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Obtain-consistent-outputs-for-unique-records-in-a-dataset/m-p/677777#M36791</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-19T12:40:00Z</dc:date>
    </item>
  </channel>
</rss>

