<?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: One way distribution of multiple variables: PCT from total without 0 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/One-way-distribution-of-multiple-variables-PCT-from-total/m-p/847733#M335154</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value Invoice_fmt
0='0'
0&amp;lt;-10000='0-10K'
10000&amp;lt;-20000='10K-20K'
20000&amp;lt;-30000='20K-30K'
30000&amp;lt;-40000='30K-40K'
40000&amp;lt;-high='40K+'
;
Run;
proc  format;
value Cylinders_Fmt
.='    Null'
3,4='   3,4'
5,6='  5,6'
8=' 8'
10,12='10,12'
;
Run;


 
Data cars;
set SASHelp.cars;
IF _N_&amp;lt;=20 then  Invoice=0;
Run;
proc sql;
create table temp1 as
select 'Invoice' as field length=80,put(Invoice,Invoice_fmt.) as Invoice length=80,
       count(*) as count,
	   calculated count/(select count(*)  as total from cars )as pct format=percent8.2,
case when calculated Invoice='0' then .
	 else  calculated count/(select count(*)  as total from cars where invoice ne 0)
end as pct_without0 format=percent8.2
from cars
group by calculated Invoice;

create table temp2 as
select 'Origin' as field length=80,Origin as Invoice length=80,
       count(*) as count,
	   calculated count/(select count(*)  as total from cars )as pct format=percent8.2,
	   calculated pct as  pct_without0 format=percent8.2
from cars
group by Origin
order by count desc;

create table temp3 as
select 'Cylinders' as field length=80,put(Cylinders,Cylinders_Fmt.) as Invoice length=80,
       count(*) as count,
	   calculated count/(select count(*)  as total from cars )as pct format=percent8.2,
	   calculated pct as  pct_without0 format=percent8.2
from cars
group by calculated Invoice
;
quit;
data want;
 set temp1-temp3;
run;
options missing=' ';
proc report data=want nowd spanrows;
define field/group order=data style(column)={vjust=m};
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1670227267686.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78021iB34EB31493B28AB6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1670227267686.png" alt="Ksharp_0-1670227267686.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Dec 2022 08:01:27 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-12-05T08:01:27Z</dc:date>
    <item>
      <title>One way distribution of multiple variables: PCT from total without 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-way-distribution-of-multiple-variables-PCT-from-total/m-p/847721#M335150</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I want to calculate distribution of multiple variables (One-way distribution for each variable).&lt;/P&gt;
&lt;P&gt;In each distribution I want to calculate:&lt;/P&gt;
&lt;P&gt;Count (number of rows in the category)&lt;/P&gt;
&lt;P&gt;PCT( percent of number of rows in category from total rows)&lt;/P&gt;
&lt;P&gt;PCT_without_0( Like PCT but without taking into account rows in category 0 if exists)&lt;/P&gt;
&lt;P&gt;Here is my attempt to do it&amp;nbsp; .&lt;/P&gt;
&lt;P&gt;The problems :&lt;/P&gt;
&lt;P&gt;1- I don't know how to calculate&amp;nbsp;PCT_without_0&lt;/P&gt;
&lt;P&gt;2-The order of rows of distribution by&amp;nbsp;Cylinders is not as I wish,I want the order will be same as in proc format:&lt;/P&gt;
&lt;P&gt;'Null','3,4','5,6','8','10,12'&lt;/P&gt;
&lt;P&gt;3-I want to put all distributions in one Report such that value in field column will not repeat&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is wanted report,&lt;/P&gt;
&lt;P&gt;What is the best way to do it?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ronein_0-1670219633783.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78019i2C2256BCF9358F37/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ronein_0-1670219633783.png" alt="Ronein_0-1670219633783.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value Invoice_fmt
0='0'
0&amp;lt;-10000='0-10K'
10000&amp;lt;-20000='10K-20K'
20000&amp;lt;-30000='20K-30K'
30000&amp;lt;-40000='30K-40K'
40000&amp;lt;-high='40K+'
;
Run;
proc  format;
value Cylinders_Fmt
.='Null'
3,4='3,4'
5,6='5,6'
8='8'
10,12='10,12'
;
Run;


 
Data cars;
set SASHelp.cars;
IF _N_&amp;lt;=20 then  Invoice=0;
Run;
proc sql;
select put(Invoice,Invoice_fmt.) as Invoice,
       count(*) as count,
	   calculated count/(select count(*)  as total from cars )as pct format=percent8.1
from cars
group by calculated Invoice
;
quit;

proc sql;
select Origin,
       count(*) as count,
	   calculated count/(select count(*)  as total from cars )as pct format=percent8.1
from cars
group by Origin
order by count desc
;
quit;


proc sql;
select put(Cylinders,Cylinders_Fmt.) as Cylinders,
       count(*) as count,
	   calculated count/(select count(*)  as total from cars )as pct format=percent8.1
from cars
group by calculated Cylinders
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 05:56:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-way-distribution-of-multiple-variables-PCT-from-total/m-p/847721#M335150</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-12-05T05:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: One way distribution of multiple variables: PCT from total without 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-way-distribution-of-multiple-variables-PCT-from-total/m-p/847733#M335154</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value Invoice_fmt
0='0'
0&amp;lt;-10000='0-10K'
10000&amp;lt;-20000='10K-20K'
20000&amp;lt;-30000='20K-30K'
30000&amp;lt;-40000='30K-40K'
40000&amp;lt;-high='40K+'
;
Run;
proc  format;
value Cylinders_Fmt
.='    Null'
3,4='   3,4'
5,6='  5,6'
8=' 8'
10,12='10,12'
;
Run;


 
Data cars;
set SASHelp.cars;
IF _N_&amp;lt;=20 then  Invoice=0;
Run;
proc sql;
create table temp1 as
select 'Invoice' as field length=80,put(Invoice,Invoice_fmt.) as Invoice length=80,
       count(*) as count,
	   calculated count/(select count(*)  as total from cars )as pct format=percent8.2,
case when calculated Invoice='0' then .
	 else  calculated count/(select count(*)  as total from cars where invoice ne 0)
end as pct_without0 format=percent8.2
from cars
group by calculated Invoice;

create table temp2 as
select 'Origin' as field length=80,Origin as Invoice length=80,
       count(*) as count,
	   calculated count/(select count(*)  as total from cars )as pct format=percent8.2,
	   calculated pct as  pct_without0 format=percent8.2
from cars
group by Origin
order by count desc;

create table temp3 as
select 'Cylinders' as field length=80,put(Cylinders,Cylinders_Fmt.) as Invoice length=80,
       count(*) as count,
	   calculated count/(select count(*)  as total from cars )as pct format=percent8.2,
	   calculated pct as  pct_without0 format=percent8.2
from cars
group by calculated Invoice
;
quit;
data want;
 set temp1-temp3;
run;
options missing=' ';
proc report data=want nowd spanrows;
define field/group order=data style(column)={vjust=m};
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1670227267686.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78021iB34EB31493B28AB6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1670227267686.png" alt="Ksharp_0-1670227267686.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 08:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-way-distribution-of-multiple-variables-PCT-from-total/m-p/847733#M335154</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-12-05T08:01:27Z</dc:date>
    </item>
  </channel>
</rss>

