<?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: Using SAS to pick the largest value within one variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-pick-the-largest-value-within-one-variable/m-p/370201#M275667</link>
    <description>&lt;P&gt;Here is one way:&lt;/P&gt;
&lt;PRE&gt;proc format;
  value symptom
  9=0
  ;
run;

data want (drop=i);&lt;BR /&gt; set have;&lt;BR /&gt; array symptoms(*) cough--flu;&lt;BR /&gt; do i=1 to dim(symptoms);&lt;BR /&gt;   symptoms(i)=put(symptoms(i),symptom.);&lt;BR /&gt; end;&lt;BR /&gt; anysymptom=max(of symptoms(*));&lt;BR /&gt;run;&lt;BR /&gt;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
    <pubDate>Sat, 24 Jun 2017 00:19:50 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-06-24T00:19:50Z</dc:date>
    <item>
      <title>Using SAS to pick the largest value within one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-pick-the-largest-value-within-one-variable/m-p/370199#M275665</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need some guidance on&amp;nbsp;the following:&lt;/P&gt;&lt;P&gt;My dataset contains 45 observations and 4 variables: cough, fever, sweats, flu; each variable is numerical with choices 1=&amp;lt;2 months, 2=3-4 months, 3=5-6 months, 4=&amp;gt;6 months, 9=unknown.&lt;/P&gt;&lt;P&gt;I need to create a new variable called 'anysymptom' where it would give me the longest duration for any of these symptoms (e.g. for observation 1 that has cough=1 fever=2 sweats=4 flu=9, the new variable would return 4, which is &amp;gt;6 months).&lt;/P&gt;&lt;P&gt;There are also missing values for some of the observations.&lt;/P&gt;&lt;P&gt;Is there a function I could utilize for this?&lt;/P&gt;&lt;P&gt;Any advise is appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 23:39:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-pick-the-largest-value-within-one-variable/m-p/370199#M275665</guid>
      <dc:creator>michan22</dc:creator>
      <dc:date>2017-06-23T23:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS to pick the largest value within one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-pick-the-largest-value-within-one-variable/m-p/370200#M275666</link>
      <description>&lt;P&gt;&lt;STRONG&gt;anysymptom = max(ifn(&lt;SPAN&gt;cough eq 9, ., cough),&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ifn(fever eq 9, ., fever), &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ifn(sweats eq 9, ., sweats), &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ifn(flu eq 9, ., flu));&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;If there were a lot of variables you could use an array and a loop.&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 23:52:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-pick-the-largest-value-within-one-variable/m-p/370200#M275666</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-06-23T23:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS to pick the largest value within one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-pick-the-largest-value-within-one-variable/m-p/370201#M275667</link>
      <description>&lt;P&gt;Here is one way:&lt;/P&gt;
&lt;PRE&gt;proc format;
  value symptom
  9=0
  ;
run;

data want (drop=i);&lt;BR /&gt; set have;&lt;BR /&gt; array symptoms(*) cough--flu;&lt;BR /&gt; do i=1 to dim(symptoms);&lt;BR /&gt;   symptoms(i)=put(symptoms(i),symptom.);&lt;BR /&gt; end;&lt;BR /&gt; anysymptom=max(of symptoms(*));&lt;BR /&gt;run;&lt;BR /&gt;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jun 2017 00:19:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-pick-the-largest-value-within-one-variable/m-p/370201#M275667</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-24T00:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS to pick the largest value within one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-pick-the-largest-value-within-one-variable/m-p/370202#M275668</link>
      <description>&lt;P&gt;If the 9 wasn't there this would be much easier, there's the LARGEST/MAX functions. This probably could be tweaked but I suspect&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16777"&gt;@WarrenKuhfeld&lt;/a&gt;&amp;nbsp;is probably the easiest or some form of a basic loop where you can ignore the 9.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this solution, I use the LARGEST() function and loop if it's a 9 so you're not looping through all the variables, only until you find one the largest that's not a&amp;nbsp;9.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    a=1;
    b=2;
    c=3;
    d=9;
    output;
    a=2;
    b=3;
    c=3;
    d=4;
    output;
    a=9;
    b=9;
    c=9;
    d=9;
    output;
run;

data want;
    set test;

    array vars(*) a b c d;
    
    maxv=.; i=1;

    do until (maxv ne 9 or i=dim(vars));       
        maxV=largest(i, of vars(*));
        i+1;
    end;

    if maxV=9 then maxV=.;
       
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Jun 2017 00:20:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-pick-the-largest-value-within-one-variable/m-p/370202#M275668</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-24T00:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS to pick the largest value within one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-pick-the-largest-value-within-one-variable/m-p/370206#M275669</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;LONGEST=max(FLUE*(FLUE&amp;lt;9), COUGH*(COUGH&amp;lt;9), SWEAT*(SWEAT&amp;lt;9), FEVER*(FEVER&amp;lt;9));&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jun 2017 01:32:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-pick-the-largest-value-within-one-variable/m-p/370206#M275669</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-06-24T01:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS to pick the largest value within one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-pick-the-largest-value-within-one-variable/m-p/370211#M275670</link>
      <description>&lt;P&gt;Thank you all for the wonderful advice!&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jun 2017 02:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-pick-the-largest-value-within-one-variable/m-p/370211#M275670</guid>
      <dc:creator>michan22</dc:creator>
      <dc:date>2017-06-24T02:55:37Z</dc:date>
    </item>
  </channel>
</rss>

