<?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: proc means, calculating statistics for multiple flags at once in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-means-calculating-statistics-for-multiple-flags-at-once/m-p/599857#M173245</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/3443"&gt;@Kc2&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see two options:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can obtain the nine statistics in one step, but in the form of a 3x3 matrix (rather than a row vector):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
class both knee hip;
var age;
ways 1;
output out=want0(drop=_type_ _freq_ where=(_level_=2)) median= p25= p75= / autoname levels;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you could use PROC TRANSPOSE and/or a DATA step to restructure dataset WANT0, if necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you can first prepare a view and then get the desired result directly (with a slightly different naming convention and order of variables, though):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vhave / view=vhave;
set have;
hip =ifn(hip, age,.);
knee=ifn(knee,age,.);
both=ifn(both,age,.);
run;

proc summary data=vhave;
var hip knee both;
output out=want(drop=_:) median= p25= p75= / autoname;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 28 Oct 2019 16:20:47 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2019-10-28T16:20:47Z</dc:date>
    <item>
      <title>proc means, calculating statistics for multiple flags at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-calculating-statistics-for-multiple-flags-at-once/m-p/599793#M173204</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;does anyone know if you can calculate summary statistics for multiple flags at once.?data have;&lt;BR /&gt;input id $ age hip $ knee $ both$;&lt;BR /&gt;datalines;&lt;BR /&gt;AB01 55 1 0 0&lt;BR /&gt;AB01 65 0 1 1&lt;BR /&gt;AC01 65 0 1 0&lt;BR /&gt;AC01 70 0 1 0&lt;BR /&gt;AC01 75 1 0 1&lt;BR /&gt;AD01 50 0 1 0&lt;BR /&gt;AD01 60 0 1 0&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;I want to do the summary statistics by age where each flag=1.&lt;/P&gt;
&lt;P&gt;I know I can do it in 3 steps with a where condition but I am wondering if I can do it in one step and have an output like this:&lt;/P&gt;
&lt;P&gt;median_hip p25_hip p75_hip median_knee&amp;nbsp;p25_knee p75_knee&amp;nbsp;median_both p25_both p75_both&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;KC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 13:48:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-calculating-statistics-for-multiple-flags-at-once/m-p/599793#M173204</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2019-10-28T13:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: proc means, calculating statistics for multiple flags at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-calculating-statistics-for-multiple-flags-at-once/m-p/599795#M173206</link>
      <description>&lt;P&gt;I'm afraid this is unclear. What variable do you want to compute summary statistics on?? Do you want the mean of AGE? That doesn't make sense you said you want the summary statistics BY AGE. There are no other numeric variables to compute summary statistics on.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 14:16:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-calculating-statistics-for-multiple-flags-at-once/m-p/599795#M173206</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-28T14:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: proc means, calculating statistics for multiple flags at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-calculating-statistics-for-multiple-flags-at-once/m-p/599822#M173224</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/3443"&gt;@Kc2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;does anyone know if you can calculate summary statistics for multiple flags at once.?data have;&lt;BR /&gt;input id $ age hip $ knee $ both$;&lt;BR /&gt;datalines;&lt;BR /&gt;AB01 55 1 0 0&lt;BR /&gt;AB01 65 0 1 1&lt;BR /&gt;AC01 65 0 1 0&lt;BR /&gt;AC01 70 0 1 0&lt;BR /&gt;AC01 75 1 0 1&lt;BR /&gt;AD01 50 0 1 0&lt;BR /&gt;AD01 60 0 1 0&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;I want to do the summary statistics by age where each flag=1.&lt;/P&gt;
&lt;P&gt;I know I can do it in 3 steps with a where condition but I am wondering if I can do it in one step and have an output like this:&lt;/P&gt;
&lt;P&gt;median_hip p25_hip p75_hip median_knee&amp;nbsp;p25_knee p75_knee&amp;nbsp;median_both p25_both p75_both&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;KC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I think you need to provide a great deal of details on what you mean. Since you show values of 1/0 for hip and knee the median, p25 or p75 values will be either 1 or 0. Is that what you intend??? And what do you mean by "median_both"? I think that you need to be very explicit with example input data and what you would expect as the actual result for this, especially that "both".&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 14:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-calculating-statistics-for-multiple-flags-at-once/m-p/599822#M173224</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-28T14:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: proc means, calculating statistics for multiple flags at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-calculating-statistics-for-multiple-flags-at-once/m-p/599827#M173228</link>
      <description>&lt;P&gt;I would like to do a proc means&amp;nbsp; on the variable age and get the median, qand the 25 and 75 percentile where each of the flags are equal to 1. I can do it with a where condition in 3 steps&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the flags are numeric, I made a typo previously&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;input id $ age hip&amp;nbsp; knee&amp;nbsp; both;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;datalines;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AB01 55 1 0 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AB01 65 0 1 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AC01 65 0 1 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AC01 70 0 1 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AC01 75 1 0 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AD01 50 0 1 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AD01 60 0 1 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc means data=have noprint;&lt;BR /&gt;where hip=1;&lt;BR /&gt;var age;&lt;BR /&gt;output out=want1(drop=_type_ _freq_) median= p25= p75= / autoname ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc means data=have noprint;&lt;BR /&gt;where knee=1;&lt;BR /&gt;var age;&lt;BR /&gt;output out=want2(drop=_type_ _freq_) median= p25= p75= / autoname ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc means data=have noprint;&lt;BR /&gt;where both=1;&lt;BR /&gt;var age;&lt;BR /&gt;output out=want3(drop=_type_ _freq_) median= p25= p75= / autoname ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can I do it in one step , where&amp;nbsp; I get the median and the percentiles of the age variable when each flag =1?&lt;/P&gt;
&lt;P&gt;I would get one observation:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;median_hip p25_hip p75_hip&amp;nbsp; &amp;nbsp; &amp;nbsp; median_knee&amp;nbsp;p25_knee p75_knee&amp;nbsp; &amp;nbsp; &amp;nbsp; median_both p25_both p75_both&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 14:57:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-calculating-statistics-for-multiple-flags-at-once/m-p/599827#M173228</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2019-10-28T14:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: proc means, calculating statistics for multiple flags at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-calculating-statistics-for-multiple-flags-at-once/m-p/599857#M173245</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/3443"&gt;@Kc2&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see two options:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can obtain the nine statistics in one step, but in the form of a 3x3 matrix (rather than a row vector):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
class both knee hip;
var age;
ways 1;
output out=want0(drop=_type_ _freq_ where=(_level_=2)) median= p25= p75= / autoname levels;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you could use PROC TRANSPOSE and/or a DATA step to restructure dataset WANT0, if necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you can first prepare a view and then get the desired result directly (with a slightly different naming convention and order of variables, though):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vhave / view=vhave;
set have;
hip =ifn(hip, age,.);
knee=ifn(knee,age,.);
both=ifn(both,age,.);
run;

proc summary data=vhave;
var hip knee both;
output out=want(drop=_:) median= p25= p75= / autoname;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Oct 2019 16:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-calculating-statistics-for-multiple-flags-at-once/m-p/599857#M173245</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-10-28T16:20:47Z</dc:date>
    </item>
  </channel>
</rss>

