<?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: picking specific observation longitudinal data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/picking-specific-observation-longitudinal-data/m-p/401522#M278740</link>
    <description>&lt;P&gt;Hi novinosrin,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It didn't work. I am trying to play with it. One idea is to do a two step approach. What do you think if I first made the data look like this by making all ID values into picking the most severe. then running a if last.id. How would I make it change all the values per ID to the most severe...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; severity&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; moderate&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;moderate&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; moderate&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; moderate&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; severe&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; severe&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; severe&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; severe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Oct 2017 21:46:58 GMT</pubDate>
    <dc:creator>Jest</dc:creator>
    <dc:date>2017-10-05T21:46:58Z</dc:date>
    <item>
      <title>picking specific observation longitudinal data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/picking-specific-observation-longitudinal-data/m-p/401498#M278736</link>
      <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a longitudinal dataset with a variable that describes disease severity (mild, moderate, severe). Since this is longitudinal subjects may have at some point been mild then became moderate or severe throughout the study. Some the opposite. I would like to pick the most severe for each subject regardless of when. I am pasting below how the data appears:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; Severity&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mild&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mild&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moderate&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moderate&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moderate&amp;nbsp;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mild&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; severe&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; severe&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mild&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mild&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mild&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mild&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How I want the data to look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Severity&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moderate&amp;nbsp;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; severe&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mild&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is the best way to achieve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 20:05:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/picking-specific-observation-longitudinal-data/m-p/401498#M278736</guid>
      <dc:creator>Jest</dc:creator>
      <dc:date>2017-10-05T20:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: picking specific observation longitudinal data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/picking-specific-observation-longitudinal-data/m-p/401503#M278737</link>
      <description>&lt;P&gt;Untested, let me know if this doesn't work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input ID Severity : $10.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 severe&lt;BR /&gt;1 mild&lt;BR /&gt;1 moderate&lt;BR /&gt;1 mild&lt;BR /&gt;2 moderate&lt;BR /&gt;2 mild&lt;BR /&gt;2 severe&lt;BR /&gt;2 mild&lt;BR /&gt;3 mild&lt;BR /&gt;3 mild&lt;BR /&gt;3 moderate&lt;BR /&gt;3 mild&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by id;&lt;BR /&gt;retain t;&lt;BR /&gt;if first.id then t=severity;&lt;BR /&gt;else if t ne 'severe' and severity ne 'mild' then t=severity;&lt;BR /&gt;if last.id;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 20:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/picking-specific-observation-longitudinal-data/m-p/401503#M278737</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-10-05T20:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: picking specific observation longitudinal data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/picking-specific-observation-longitudinal-data/m-p/401510#M278738</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/128691"&gt;@Jest&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;HI,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the best way to achieve this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;"Best" would depend on what you are measuring. Best by shortest execution time, shortest code, easiest to understand/ maintain code could all be used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you have a variable that has an order, if this were my data I would have read the data so that I had and ordinal numeric variable with the "least severe" or what ever term would apply with the value of 1 to a larger integer for the "most severe". There would also be an associated display format to display the desired text when used.&lt;/P&gt;
&lt;P&gt;Which would make my code for your request look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc summary data=have nway;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; class id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; var severity;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output out=idsummary max= ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;Which would have the maximum value of that numeric severity variable for each ID value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are a number of other things possible with numeric ordinals that aren't possible with most character variables.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 20:45:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/picking-specific-observation-longitudinal-data/m-p/401510#M278738</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-05T20:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: picking specific observation longitudinal data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/picking-specific-observation-longitudinal-data/m-p/401519#M278739</link>
      <description>&lt;P&gt;Thank you Ballardw. Proc summary worked after converting the variable to numeric.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, is there a way to retain the rest of the variables in the dataset. They don't very across time.&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>Thu, 05 Oct 2017 21:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/picking-specific-observation-longitudinal-data/m-p/401519#M278739</guid>
      <dc:creator>Jest</dc:creator>
      <dc:date>2017-10-05T21:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: picking specific observation longitudinal data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/picking-specific-observation-longitudinal-data/m-p/401522#M278740</link>
      <description>&lt;P&gt;Hi novinosrin,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It didn't work. I am trying to play with it. One idea is to do a two step approach. What do you think if I first made the data look like this by making all ID values into picking the most severe. then running a if last.id. How would I make it change all the values per ID to the most severe...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; severity&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; moderate&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;moderate&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; moderate&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; moderate&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; severe&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; severe&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; severe&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; severe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 21:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/picking-specific-observation-longitudinal-data/m-p/401522#M278740</guid>
      <dc:creator>Jest</dc:creator>
      <dc:date>2017-10-05T21:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: picking specific observation longitudinal data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/picking-specific-observation-longitudinal-data/m-p/401525#M278741</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/128691"&gt;@Jest&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you Ballardw. Proc summary worked after converting the variable to numeric.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, is there a way to retain the rest of the variables in the dataset. They don't very across time.&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;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show the code you used to add or replace the severity variable. If done correctly it shouldn't have affected any of the other variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Or if you are talking about adding the single result in the summary back to the other data matching the id variable?&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table severityadded as
   select a.*, b.severity as maxseverity
   from have as a left join
        idsummary as b
        on a.id=b.id;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Oct 2017 21:55:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/picking-specific-observation-longitudinal-data/m-p/401525#M278741</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-05T21:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: picking specific observation longitudinal data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/picking-specific-observation-longitudinal-data/m-p/401526#M278742</link>
      <description>&lt;P&gt;I just ran this code after converting the variable to numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc summary data=have nway;&lt;BR /&gt;class id;&lt;BR /&gt;var severe;&lt;BR /&gt;output out=data.idsummary max= ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so the output dataset picks the most severe per ID over time.. It includes ID, _Type_, _FREQ_ and the variable severe. If possible I would like the output dataset to also include all the remainder variable in the original dataset (have) as well. I could technically go back and run an if last.ID on the original dataset and then merge it with the idsummary one which includes the severity variable....but is there a way to just do that in the proc summary code above....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 21:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/picking-specific-observation-longitudinal-data/m-p/401526#M278742</guid>
      <dc:creator>Jest</dc:creator>
      <dc:date>2017-10-05T21:55:22Z</dc:date>
    </item>
  </channel>
</rss>

