<?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 do I sort though character variables and ID's to make a simple table with averages? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/341010#M272744</link>
    <description>I added a few tables the type of data I am looking at.&lt;BR /&gt;Also thank you for your suggestion. I'm pretty new to sas, I have seen the class command, but I will definitely look more into it. I think it can be useful!</description>
    <pubDate>Wed, 15 Mar 2017 00:38:36 GMT</pubDate>
    <dc:creator>Curly</dc:creator>
    <dc:date>2017-03-15T00:38:36Z</dc:date>
    <item>
      <title>how do I sort though character variables and ID's to make a simple table with averages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/340974#M272739</link>
      <description>&lt;P&gt;Hi everyone!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need a bit of help thinking this out and finding the best way to&amp;nbsp;handle this. Any suggestions on how I should attempt this are appreciate! Thank you in advanced!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have a data set with 3 variables, ID - lab name - lab result. Not all the results are numeric and this lab result variable is a character variable (so is the lab name variable). Every ID has many lab names. There are only 70 ID's but over 56,000 labs and about 500&amp;nbsp;different labs within this group .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;numeric&amp;nbsp; character&amp;nbsp; character&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;labname&lt;/TD&gt;&lt;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gt;290&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;16&lt;/TD&gt;&lt;TD&gt;Total protine&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;16&lt;/TD&gt;&lt;TD&gt;platelets&lt;/TD&gt;&lt;TD&gt;140&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;23&lt;/TD&gt;&lt;TD&gt;carbon dioxide&lt;/TD&gt;&lt;TD&gt;26&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;23&lt;/TD&gt;&lt;TD&gt;Bun&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;23&lt;/TD&gt;&lt;TD&gt;Total protine&lt;/TD&gt;&lt;TD&gt;8.5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;23&lt;/TD&gt;&lt;TD&gt;protine&lt;/TD&gt;&lt;TD&gt;negative&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;46&lt;/TD&gt;&lt;TD&gt;Glucose&lt;/TD&gt;&lt;TD&gt;130&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;46&lt;/TD&gt;&lt;TD&gt;Bun&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the end I want to have a table where the average result in each lab test is shown per ID. So I know i need to keep only the results that have numeric variables. It only need to be for those numeric values&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="0" border="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;protine&lt;/TD&gt;&lt;TD&gt;platelets&lt;/TD&gt;&lt;TD&gt;glucose&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;average&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;average&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;16&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;23&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I feel there are a 100 ways I can proceed.&lt;/P&gt;&lt;P&gt;I know have to find a way to sort through the results, and keep only those that are numeric.&lt;/P&gt;&lt;P&gt;I want to transpose the data, but so far this hasn't worked.&lt;/P&gt;&lt;P&gt;I'm thinking of writing a macro where I would feed it the ID's and have it run and gather all the test results for that ID. However I think I might be making this too complicated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any&amp;nbsp;suggestions would be super appreciated! Thank You&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 00:34:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/340974#M272739</guid>
      <dc:creator>Curly</dc:creator>
      <dc:date>2017-03-15T00:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: how do I sort though character variables and ID's to make a simple table with averages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/340977#M272740</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/129889"&gt;@Curly&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need a bit of help thinking this out and finding the best way to&amp;nbsp;handle this. Any suggestions on how I should attempt this are appreciate! Thank you in advanced!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have a data set with 3 variables, ID - lab name - lab result. Not all the results are numeric and this lab result variable is a character variable (so is the lab name variable). Every ID has many lab names. There are only 70 ID's but over 56,000 labs and about 500&amp;nbsp;different labs within this group .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the end I want to have a table where the average result in each lab test is shown per ID. So I know i need to drop the results that have numeric variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel there are a 100 ways I can proceed.&lt;/P&gt;
&lt;P&gt;I know have to find a way to sort through the results, and keep only those that are numeric.&lt;/P&gt;
&lt;P&gt;I want to transpose the data, but so far this hasn't worked.&lt;/P&gt;
&lt;P&gt;I'm thinking of writing a macro where I would feed it the ID's and have it run and gather all the test results for that ID. However I think I might be making this too complicated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any&amp;nbsp;suggestions would be super appreciated! Thank You&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm having a super hard time following this...please post sample data and output to illustrate what you want. It doesn't have to be real data, but data that illustrates your problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to do the same thing multiple times, the usual method is a BY or CLASS statement with PROC MEANS but it seems like you also need to add some data cleaning steps to get the data to a form that works for you first.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I highly suggest posting what you have and what you want and we can suggest the various methods, sometimes we disagree on the best methods on here &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A quick example of one way of calculating statistics per group:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as&amp;nbsp;
select *, mean(weight) as weight_by_sex
from sashelp.class
group by sex
order by name;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2017 22:10:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/340977#M272740</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-14T22:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: how do I sort though character variables and ID's to make a simple table with averages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/340990#M272741</link>
      <description>&lt;P&gt;Here's one approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a numeric variable holding the lab result, when that is possible:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;numeric_result = input(lab_result, ??12.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At this point, the lazy way would be to compute means of the numeric variable. &amp;nbsp;But an intermediate step would normally be appropriate:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=converted;&lt;/P&gt;
&lt;P&gt;where numeric_result=.;&lt;/P&gt;
&lt;P&gt;tables lab_result;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This shows all the lab results that could not be converted directly to numeric. &amp;nbsp;You may see patterns there that could be used (such as ignoring units of measure after a numeric value).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have computed as many numeric values as possible, then generate the mean values.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2017 22:58:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/340990#M272741</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-14T22:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: how do I sort though character variables and ID's to make a simple table with averages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/340996#M272742</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/129889"&gt;@Curly&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the end I want to have a table where the average result in each lab test is shown per ID. So I know i need to &lt;STRONG&gt;&lt;FONT color="#ff0000"&gt;drop&lt;/FONT&gt;&lt;/STRONG&gt; the results that have numeric variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have to say that this statement is very confusing. If you drop numeric values what dos is mean to have an "average result"?&lt;/P&gt;
&lt;P&gt;Perhaps you mean something like a MODE, the most common count of the&amp;nbsp;non-numeric values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example data, input and out for the input, goes a long way to clarifying meaning.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2017 23:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/340996#M272742</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-14T23:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: how do I sort though character variables and ID's to make a simple table with averages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/341009#M272743</link>
      <description>So sorry about the typo. I mean to drop the results that appear as characters, and keep all the results that are numeric. Thank you for that!</description>
      <pubDate>Wed, 15 Mar 2017 00:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/341009#M272743</guid>
      <dc:creator>Curly</dc:creator>
      <dc:date>2017-03-15T00:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: how do I sort though character variables and ID's to make a simple table with averages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/341010#M272744</link>
      <description>I added a few tables the type of data I am looking at.&lt;BR /&gt;Also thank you for your suggestion. I'm pretty new to sas, I have seen the class command, but I will definitely look more into it. I think it can be useful!</description>
      <pubDate>Wed, 15 Mar 2017 00:38:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/341010#M272744</guid>
      <dc:creator>Curly</dc:creator>
      <dc:date>2017-03-15T00:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: how do I sort though character variables and ID's to make a simple table with averages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/341011#M272745</link>
      <description>&lt;P&gt;It looks to be test issue. Certain tests report numbers, others report text. Ideally you'd know which was which, but it's not difficult to approximate this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data numeric;
set have;

result_number&amp;nbsp; = input(labresults, ?? best12.);

run;

proc means data=numeric noprint nway;&amp;nbsp;
class id labname;
var result_number;
output out=summary mean(result_number) = average;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then transpose the result to the shown format - PROC TRANSPOSE. The variables without a numeric value will sort of filter themselves out. Or you can explicitly extract those results by adding a WHERE to the PROC MEANS to exclude missing data.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 00:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/341011#M272745</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-15T00:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: how do I sort though character variables and ID's to make a simple table with averages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/341013#M272746</link>
      <description>Thank you!</description>
      <pubDate>Wed, 15 Mar 2017 00:45:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-sort-though-character-variables-and-ID-s-to-make-a/m-p/341013#M272746</guid>
      <dc:creator>Curly</dc:creator>
      <dc:date>2017-03-15T00:45:07Z</dc:date>
    </item>
  </channel>
</rss>

