<?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 Tabulate: Different Vars based on Class Value in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89125#M25429</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Cynthia,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The table has three columns, but the data has 4 columns (vendor, fruittype, height, weight).&amp;nbsp; This is all imaginary data to simplify an bigger, more complicated data structure.&amp;nbsp; The measures could certainly change, I have some variables that I need to sum, others are mean, etc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Aug 2012 12:36:23 GMT</pubDate>
    <dc:creator>wcpatton</dc:creator>
    <dc:date>2012-08-10T12:36:23Z</dc:date>
    <item>
      <title>Proc Tabulate: Different Vars based on Class Value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89118#M25422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Suppose my dataset is about fruits, it has two values for fruit: Apples and Oranges.&amp;nbsp; Being so different, I've decided that I want to measure Oranges by Weight and Apples by Height.&amp;nbsp; My data would then have 3 columns, plus a 4th for vendor.&amp;nbsp; I'm looking for a way to present this data in a proc tabulate side by side.&amp;nbsp; Something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid #000000; width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;/TH&gt;&lt;TH style="text-align: center;" valign="middle"&gt;Oranges&lt;/TH&gt;&lt;TH style="text-align: center;" valign="middle"&gt;Apples&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;Vendor&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;Weight&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;Height&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Jim&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;15&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Sally&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;14&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any thoughts about the possibility of changing the vars used based on the class value?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Aug 2012 17:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89118#M25422</guid>
      <dc:creator>wcpatton</dc:creator>
      <dc:date>2012-08-09T17:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate: Different Vars based on Class Value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89119#M25423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Basically you have to create a new analysis variable.&amp;nbsp; The below is untested, but I think does what you want:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data vtemp / view=vtemp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if fruit='oranges' then measure=weight;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if fruit='apples' then measure=height;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;** And let's include the measure description in the fruit value **;&lt;/P&gt;&lt;P&gt;proc format ;&lt;/P&gt;&lt;P&gt; value $frt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'oranges' = 'Oranges - Weight' &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'apples'='Apples - Height';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc tabulate data=vtemp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; class fruit vendor;&amp;nbsp; var measure;&lt;/P&gt;&lt;P&gt;&amp;nbsp; tables vendor,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fruit * mean='Mean' * measure= ' 'l&lt;/P&gt;&lt;P&gt;&amp;nbsp; format fruit $frt. ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of course you could also make a new class variable to identify the measure being used, and forget the format in the above example.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Aug 2012 18:31:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89119#M25423</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2012-08-09T18:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate: Different Vars based on Class Value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89120#M25424</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I see what you're going for there, it works pretty well for the 2x3 table... In actuality, my data is more like 12x12, so I have to figure out if it's worth coding all those and hope it never changes.&amp;nbsp; I'm looking into doing two tabulates, outputting the data as a dataset then merging those back together.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Aug 2012 18:49:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89120#M25424</guid>
      <dc:creator>wcpatton</dc:creator>
      <dc:date>2012-08-09T18:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate: Different Vars based on Class Value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89121#M25425</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Then generalize using macrovars, as in:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let fruitlist= oranges apples;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let vars&amp;nbsp;&amp;nbsp;&amp;nbsp; = weight&amp;nbsp; height;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data vtemp / view=vtemp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array meas {*} &amp;amp;vars;&lt;/P&gt;&lt;P&gt;&amp;nbsp; W=&amp;nbsp; findw("&amp;amp;fruitlist",trim(fruit),' ','E');&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; measure=&amp;nbsp; meas{W};&lt;/P&gt;&lt;P&gt;&amp;nbsp; descrip=scan("&amp;amp;vars",W);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc tabulate data=vtemp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; class vendor fruit descrip;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var measure;&lt;/P&gt;&lt;P&gt;&amp;nbsp; tables vendor,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fruit=' ' * descrip *&amp;nbsp;&amp;nbsp; mean*measure=' ';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Aug 2012 19:19:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89121#M25425</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2012-08-09T19:19:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate: Different Vars based on Class Value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89122#M25426</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All good ideas.&amp;nbsp; Here are a few minor ones to consider ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unless there are many different measures, it might be easier to construct macro variables along these lines:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let height_list = apples bananas pears;&lt;/P&gt;&lt;P&gt;%let weight_list = oranges blueberries;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In practice, it will be necessary to pay attention to capitalization.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it becomes necessary to control the order of the columns, that can be done but might be more involved.&amp;nbsp; You would need a macro variable to indicate the proper order, and might start using two formats.&amp;nbsp; Something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;value $order 'oranges'='01'&lt;/P&gt;&lt;P&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; 'apples'='02';&lt;/P&gt;&lt;P&gt;value $fruit '01'='oranges'&lt;/P&gt;&lt;P&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; '02'='apples';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Both could be constructed from that new macro variable that indicates the order of the columns.&amp;nbsp; Other than specifying the macro variables, no maintenance would be necessary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Aug 2012 20:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89122#M25426</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-08-09T20:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate: Different Vars based on Class Value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89123#M25427</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think, at this point, it's mostly a matter of style.&amp;nbsp; But if you stick with the notion of putting all the fruits in FRUITLIST, then just by listing them in desired order, there will be no order problem to solve.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Aug 2012 20:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89123#M25427</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2012-08-09T20:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate: Different Vars based on Class Value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89124#M25428</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, maybe I'm dense, but I don't see 4 columns. I see one column for Oranges, one column for Apples and a 3rd column for vendor. Where is the 4th column???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, do you ALWAYS want the MEAN as the statistic for your measure (height or weight) -- or could you want the MAX for one value of FRUIT and MIN for another value of FRUIT and MEAN for a different value of FRUIT?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cynthia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Aug 2012 20:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89124#M25428</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2012-08-09T20:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate: Different Vars based on Class Value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89125#M25429</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Cynthia,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The table has three columns, but the data has 4 columns (vendor, fruittype, height, weight).&amp;nbsp; This is all imaginary data to simplify an bigger, more complicated data structure.&amp;nbsp; The measures could certainly change, I have some variables that I need to sum, others are mean, etc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Aug 2012 12:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89125#M25429</guid>
      <dc:creator>wcpatton</dc:creator>
      <dc:date>2012-08-10T12:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate: Different Vars based on Class Value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89126#M25430</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you want different stats for different fruits, then you might be better off runing proc means to generate all the stats for all the variables, CLASS-ified by fruit and vendor.&amp;nbsp; Then you can select the combination of fruits, measures, and stats wanted.&amp;nbsp; PROC TABULATE then simply become a display tool, since each cell comes from a single var in a single observations in the proc means output.&amp;nbsp; That's why the example below can use the SUM= expression regardless of which stat is being reported.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is a sample using sashelp.class (use sex for fruit, and agegroup for vendor).&amp;nbsp; I also set it up so that you can get multiple measures and multiple stats for a single sex (fruit in the op example).&amp;nbsp; Fill the macrovars in the order you want the columns filled.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of course, by the time you've run the PROC MEANS, there might be better ways to display results than proc tabulate, but since that's how we started ...&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Let's say you want, in this order, mean height for women, min weight for men, then max weight for men, by agegroup:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let sexlist=&amp;nbsp; F&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; M&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; M;&lt;BR /&gt;%let vars=&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; height weight weight;&lt;BR /&gt;%let stats =&amp;nbsp;&amp;nbsp; MEAN&amp;nbsp;&amp;nbsp; MIN&amp;nbsp;&amp;nbsp;&amp;nbsp; MAX;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; set sashelp.class;&lt;BR /&gt;&amp;nbsp; agegroup=1+(age&amp;gt;14);&lt;BR /&gt;&amp;nbsp; output;&amp;nbsp;&amp;nbsp; output;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc means data=have noprint nway &amp;amp;stats;&lt;BR /&gt;&amp;nbsp; class sex agegroup;&lt;BR /&gt;&amp;nbsp; var &amp;amp;vars;&lt;BR /&gt;&amp;nbsp; output out=need;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data vtemp (KEEP=SEX AGEGROUP MEASURE DESCRIP W)/ view=vtemp;&lt;BR /&gt;&amp;nbsp; set need;&lt;BR /&gt;&amp;nbsp; array meas {*} &amp;amp;vars;&lt;BR /&gt;&amp;nbsp; do W=1 to dim(meas);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sexvalue=scan("&amp;amp;sexlist",w);&lt;BR /&gt; if sex=sexvalue then do; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; S=&amp;nbsp; scan("&amp;amp;stats",W);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _stat_=S then do; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; measure=meas{W};&lt;BR /&gt;&amp;nbsp; descrip=catx('-',scan("&amp;amp;vars",W),_stat_);&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt; end;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=vtemp out=temp;&lt;BR /&gt;&amp;nbsp; by w;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc tabulate data=temp noseps&amp;nbsp; order=data ;&lt;BR /&gt;&amp;nbsp; class agegroup sex descrip;&lt;BR /&gt;&amp;nbsp; var measure;&lt;BR /&gt;&amp;nbsp; tables agegroup,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sex * descrip=' ' * sum=' '*measure=' ';&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Aug 2012 15:03:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-Different-Vars-based-on-Class-Value/m-p/89126#M25430</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2012-08-10T15:03:33Z</dc:date>
    </item>
  </channel>
</rss>

