<?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 select maximum values for all variables with the same prefix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-maximum-values-for-all-variables-with-the-same/m-p/740834#M231490</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/314297"&gt;@catkat96&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;How can I do it so that only the last row of each id from have is merged with want?&lt;BR /&gt;I added the variable time as well, and did the merge by id date and time and it's merging rows with different times for some reason&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;1) Show your code&lt;/P&gt;
&lt;P&gt;2) Show some data for the two sets merged.&lt;/P&gt;
&lt;P&gt;3) show the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If one data set in a MERGE has values of the BY variables that do not appear in the other then you get both. If you require the output to only include matches from one of the data sets you use the IN data set option to create contribution indicators such as;&lt;/P&gt;
&lt;PRE&gt;data want; 
   merge one (in=inone)
         two (in=intwo)
   ;
   by somevar;
   if inone; /* select records that have matches from data set one*/
;&lt;/PRE&gt;
&lt;P&gt;Th IN option creates a 1/0 (true/false) temporary variable that indicates if the current record has contributions from that data set. Temporary means the variable is not written to the output data set.&lt;/P&gt;
&lt;P&gt;If inone=1 and intwo= 1 then both data sets contribute&lt;/P&gt;
&lt;P&gt;if inone=1 and intwo=0&amp;nbsp; then the current record only has items from data set one&lt;/P&gt;
&lt;P&gt;if inone=0 and intwo=1 then the current record only has items from data set two&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So this might be a solution to "time" values in one set but not the other that you are seeing. Might.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 May 2021 15:35:01 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-05-12T15:35:01Z</dc:date>
    <item>
      <title>how to select maximum values for all variables with the same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-maximum-values-for-all-variables-with-the-same/m-p/740748#M231451</link>
      <description>&lt;P&gt;I have something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select id
, date
, v3
, v4
, max(d:)

from have
group by id, date;
quit;&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where there are d1, d2, d3, d4, d5, d6, etc.&lt;/P&gt;&lt;P&gt;The system is throwing an error in the max part of the code, I assume because saying max(d:) is not right.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to do something like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively I tried&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway;
class id date;
var d: v3 v4;
output out=want max=;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But it's not workking because v3 and v4 are not numeric. If I don't include v3 and v4 it runs, but I need to include those.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: to give a bit more context, I want to do this to "merge" rows with the same ID, to end with one row per ID per date.&lt;/P&gt;&lt;P&gt;Edit 2: I want to end with all d columns as columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 09:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-select-maximum-values-for-all-variables-with-the-same/m-p/740748#M231451</guid>
      <dc:creator>catkat96</dc:creator>
      <dc:date>2021-05-12T09:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to select maximum values for all variables with the same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-maximum-values-for-all-variables-with-the-same/m-p/740766#M231458</link>
      <description>Add one more Data Step ?&lt;BR /&gt;&lt;BR /&gt;proc summary data=have nway;&lt;BR /&gt;class id date;&lt;BR /&gt;var d: ;&lt;BR /&gt;output out=want max=;&lt;BR /&gt;run;&lt;BR /&gt;data final_want;&lt;BR /&gt; merge have(keep=id date v3 v4) want;&lt;BR /&gt;by id date;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 12 May 2021 11:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-select-maximum-values-for-all-variables-with-the-same/m-p/740766#M231458</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-05-12T11:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to select maximum values for all variables with the same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-maximum-values-for-all-variables-with-the-same/m-p/740808#M231475</link>
      <description>How can I do it so that only the last row of each id from have is merged with want?&lt;BR /&gt;I added the variable time as well, and did the merge by id date and time and it's merging rows with different times for some reason</description>
      <pubDate>Wed, 12 May 2021 14:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-select-maximum-values-for-all-variables-with-the-same/m-p/740808#M231475</guid>
      <dc:creator>catkat96</dc:creator>
      <dc:date>2021-05-12T14:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to select maximum values for all variables with the same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-maximum-values-for-all-variables-with-the-same/m-p/740834#M231490</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/314297"&gt;@catkat96&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;How can I do it so that only the last row of each id from have is merged with want?&lt;BR /&gt;I added the variable time as well, and did the merge by id date and time and it's merging rows with different times for some reason&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;1) Show your code&lt;/P&gt;
&lt;P&gt;2) Show some data for the two sets merged.&lt;/P&gt;
&lt;P&gt;3) show the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If one data set in a MERGE has values of the BY variables that do not appear in the other then you get both. If you require the output to only include matches from one of the data sets you use the IN data set option to create contribution indicators such as;&lt;/P&gt;
&lt;PRE&gt;data want; 
   merge one (in=inone)
         two (in=intwo)
   ;
   by somevar;
   if inone; /* select records that have matches from data set one*/
;&lt;/PRE&gt;
&lt;P&gt;Th IN option creates a 1/0 (true/false) temporary variable that indicates if the current record has contributions from that data set. Temporary means the variable is not written to the output data set.&lt;/P&gt;
&lt;P&gt;If inone=1 and intwo= 1 then both data sets contribute&lt;/P&gt;
&lt;P&gt;if inone=1 and intwo=0&amp;nbsp; then the current record only has items from data set one&lt;/P&gt;
&lt;P&gt;if inone=0 and intwo=1 then the current record only has items from data set two&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So this might be a solution to "time" values in one set but not the other that you are seeing. Might.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 15:35:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-select-maximum-values-for-all-variables-with-the-same/m-p/740834#M231490</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-12T15:35:01Z</dc:date>
    </item>
  </channel>
</rss>

