<?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 Replace values for each ID for a variable  based on the greatest ones in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Replace-values-for-each-ID-for-a-variable-based-on-the-greatest/m-p/834442#M35879</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Subj &amp;nbsp; Age&lt;/P&gt;
&lt;P&gt;a &amp;nbsp; &amp;nbsp; &amp;nbsp;30-40&lt;/P&gt;
&lt;P&gt;a &amp;nbsp; &amp;nbsp; &amp;nbsp;30-40&lt;/P&gt;
&lt;P&gt;a &amp;nbsp; &amp;nbsp; &amp;nbsp;50-60&lt;/P&gt;
&lt;P&gt;a &amp;nbsp; &amp;nbsp; &amp;nbsp;50-60&lt;/P&gt;
&lt;P&gt;b &amp;nbsp; &amp;nbsp; &amp;nbsp;30-40&lt;/P&gt;
&lt;P&gt;b &amp;nbsp; &amp;nbsp; &amp;nbsp;30-40&lt;/P&gt;
&lt;P&gt;b &amp;nbsp; &amp;nbsp; &amp;nbsp;30-40&amp;nbsp;&lt;/P&gt;
&lt;P&gt;.................&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way, for each Subj to replace for the age variable the values with the greatest ones? In other words, 30-40 for "a" should be replaced with 50-60. Thank you in advance.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Sep 2022 10:19:03 GMT</pubDate>
    <dc:creator>NewUsrStat</dc:creator>
    <dc:date>2022-09-21T10:19:03Z</dc:date>
    <item>
      <title>Replace values for each ID for a variable  based on the greatest ones</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Replace-values-for-each-ID-for-a-variable-based-on-the-greatest/m-p/834442#M35879</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Subj &amp;nbsp; Age&lt;/P&gt;
&lt;P&gt;a &amp;nbsp; &amp;nbsp; &amp;nbsp;30-40&lt;/P&gt;
&lt;P&gt;a &amp;nbsp; &amp;nbsp; &amp;nbsp;30-40&lt;/P&gt;
&lt;P&gt;a &amp;nbsp; &amp;nbsp; &amp;nbsp;50-60&lt;/P&gt;
&lt;P&gt;a &amp;nbsp; &amp;nbsp; &amp;nbsp;50-60&lt;/P&gt;
&lt;P&gt;b &amp;nbsp; &amp;nbsp; &amp;nbsp;30-40&lt;/P&gt;
&lt;P&gt;b &amp;nbsp; &amp;nbsp; &amp;nbsp;30-40&lt;/P&gt;
&lt;P&gt;b &amp;nbsp; &amp;nbsp; &amp;nbsp;30-40&amp;nbsp;&lt;/P&gt;
&lt;P&gt;.................&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way, for each Subj to replace for the age variable the values with the greatest ones? In other words, 30-40 for "a" should be replaced with 50-60. Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 10:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Replace-values-for-each-ID-for-a-variable-based-on-the-greatest/m-p/834442#M35879</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2022-09-21T10:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Replace values for each ID for a variable  based on the greatest ones</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Replace-values-for-each-ID-for-a-variable-based-on-the-greatest/m-p/834443#M35880</link>
      <description>&lt;P&gt;what possible values do you have for age?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 10:34:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Replace-values-for-each-ID-for-a-variable-based-on-the-greatest/m-p/834443#M35880</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-09-21T10:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: Replace values for each ID for a variable  based on the greatest ones</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Replace-values-for-each-ID-for-a-variable-based-on-the-greatest/m-p/834446#M35881</link>
      <description>I have a lot of ranges. I just have to keep the highest. Ranges are: 21-25, 26-30, 31-35, 36-40, 41-45, 46-50, 51-55, 56-60, 61-65 and 66-70.</description>
      <pubDate>Wed, 21 Sep 2022 10:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Replace-values-for-each-ID-for-a-variable-based-on-the-greatest/m-p/834446#M35881</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2022-09-21T10:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: Replace values for each ID for a variable  based on the greatest ones</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Replace-values-for-each-ID-for-a-variable-based-on-the-greatest/m-p/834448#M35882</link>
      <description>&lt;P&gt;Ok . Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Subj $ Age $;
datalines;
a 30-40 
a 30-40 
a 50-60 
a 50-60 
b 30-40 
b 30-40 
b 30-40 
;

proc sql;
create table want as
   select Subj,
          (select max(Age) 
           from have 
           where a.Subj=Subj 
           group by Subj) as Age
   from have as a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Sep 2022 11:10:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Replace-values-for-each-ID-for-a-variable-based-on-the-greatest/m-p/834448#M35882</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-09-21T11:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: Replace values for each ID for a variable  based on the greatest ones</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Replace-values-for-each-ID-for-a-variable-based-on-the-greatest/m-p/834453#M35884</link>
      <description>&lt;P&gt;May I suggest that you use a numeric variable to represent age rather than a text string? The advantage (which may not make a difference in your data, I don't know) is that a text string such as 5-9 will seem to be higher (because that's how text is evaluated, alphabetically) than 21-25. And so if you had a 5-9 for a subject, you would possibly get the wrong answer. Similarly, if there are people in the 100-110 year age group, these will appear to be less than the 21-25 age group. Even if this doesn't apply to your data, it is still a good idea for you (and anyone else reading along) to make age a numeric variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This problem doesn't happen with numeric variables, since these will be evaluated numerically, either 5 or 9 is less than 25, and 100 is greater than 25. And so the code from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;would also likely fail in this more general case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    age_n=input(scan(age,1,'-'),3.);
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and then use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;'s code (or something very similar to it) to get the maximum of AGE_N.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 12:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Replace-values-for-each-ID-for-a-variable-based-on-the-greatest/m-p/834453#M35884</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-21T12:21:01Z</dc:date>
    </item>
  </channel>
</rss>

