<?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 create a table using frequencies? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-create-a-table-using-frequencies/m-p/884465#M39253</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Just for having some fun.*/
data employeesl;
    input employee $ station $ gender $ race $ StationID;
    datalines;
Smith west F B 124
Turner east M W 123
Porter north M W 125
William west F W 124
Lee south F B 126
Maine south M B 126
;
run;
proc sql;
select station,StationID,
sum(gender='M' and race='W') as White_Male,
sum(gender='F' and race='W') as White_Female,
sum(gender='M' and race='B') as Black_Male,
sum(gender='F' and race='B') as Black_Female
 from employeesl
  group by station,StationID
union all
select 'All Stations',999,
sum(gender='M' and race='W') as White_Male,
sum(gender='F' and race='W') as White_Female,
sum(gender='M' and race='B') as Black_Male,
sum(gender='F' and race='B') as Black_Female
 from employeesl
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 12 Jul 2023 11:39:21 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2023-07-12T11:39:21Z</dc:date>
    <item>
      <title>How do I create a table using frequencies?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-create-a-table-using-frequencies/m-p/884358#M39249</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, my data is similar to this:&lt;/P&gt;&lt;PRE&gt;data employeesl;&lt;BR /&gt;input employee $ station $ gender $ race $ StationID;&lt;BR /&gt;datalines;&lt;BR /&gt;Smith west F B 124&lt;BR /&gt;Turner east M W 123&lt;BR /&gt;Porter north M W 125&lt;BR /&gt;William west F W 124&lt;BR /&gt;Lee south F B 126&lt;BR /&gt;Maine south M B 126&lt;BR /&gt;;&lt;BR /&gt;run; &lt;/PRE&gt;&lt;P&gt;I am looking to create a table similar to this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Station&lt;/TD&gt;&lt;TD&gt;StationID&lt;/TD&gt;&lt;TD&gt;White Male&lt;/TD&gt;&lt;TD&gt;White Female&lt;/TD&gt;&lt;TD&gt;Black Male&lt;/TD&gt;&lt;TD&gt;Black Female&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;East&lt;/TD&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;West&lt;/TD&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;North&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;South&lt;/TD&gt;&lt;TD&gt;126&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;All Stations&lt;/TD&gt;&lt;TD&gt;999&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 15:41:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-create-a-table-using-frequencies/m-p/884358#M39249</guid>
      <dc:creator>AVUH777</dc:creator>
      <dc:date>2023-07-11T15:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a table using frequencies?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-create-a-table-using-frequencies/m-p/884367#M39250</link>
      <description>&lt;P&gt;With table as is, this is fairly close:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=employeesl;
class  station gender race stationID;
table (station*stationID all), race=''*gender=''*N='' / misstext='0';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To have the gender/race headers all in one column and expanded, you can use formats and/or combine them into a single variable and then use the single variable instead of the race*gender in proc tabulate.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the table a SAS dataset or for a report, ie PDF?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data employeesl;
    input employee $ station $ gender $ race $ StationID;
    datalines;
Smith west F B 124
Turner east M W 123
Porter north M W 125
William west F W 124
Lee south F B 126
Maine south M B 126
;
run;

*formats to control display;

proc format;
    value $ race_fmt 'B'='Black' 'W'='White' other='Other';
    value $ gender_fmt 'F'='Female' 'M'='Male' other='Other';
run;

*generic tabulate;

proc tabulate data=employeesl;
    class station gender race stationID;
    table (station*stationID all), race=''*gender=''*N='' / misstext='0';
    format gender $gender_fmt. race $race_fmt.;
run;

*combining categorical variables of race/gender;

data employeesl;
    set employeesl;
    category=catx(" ", put(race, $race_fmt.), put(gender, $gender_fmt.));
run;

*tabulate with category combined;

proc tabulate data=employeesl out=long;
    class station stationID category;
    table (station*stationID all), category=''*N='' / misstext='0';
run;

proc sort data=long;
    by descending station stationId;
run;

*output in dataset;

proc transpose data=long out=wide (drop=_:);
    by descending station stationid;
    id category;
    var N;
run;

*fill in missing and add ALL label;

data wide;
    set wide;
    array _vars _numeric_;

    do over _vars;

        if _vars=. then
            _vars=0;
    end;

    if missing(station) then
        do;
            station='All';
            call missing(stationID);
        end;
run;

*display results;

proc print data=wide noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Jul 2023 17:16:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-create-a-table-using-frequencies/m-p/884367#M39250</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-11T17:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a table using frequencies?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-create-a-table-using-frequencies/m-p/884373#M39251</link>
      <description>Thank you so much! I tried to use proc tabulate originally, but something was wrong with my table statement. This fixed it! The table is for a report.&amp;nbsp;</description>
      <pubDate>Tue, 11 Jul 2023 17:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-create-a-table-using-frequencies/m-p/884373#M39251</guid>
      <dc:creator>AVUH777</dc:creator>
      <dc:date>2023-07-11T17:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a table using frequencies?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-create-a-table-using-frequencies/m-p/884465#M39253</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Just for having some fun.*/
data employeesl;
    input employee $ station $ gender $ race $ StationID;
    datalines;
Smith west F B 124
Turner east M W 123
Porter north M W 125
William west F W 124
Lee south F B 126
Maine south M B 126
;
run;
proc sql;
select station,StationID,
sum(gender='M' and race='W') as White_Male,
sum(gender='F' and race='W') as White_Female,
sum(gender='M' and race='B') as Black_Male,
sum(gender='F' and race='B') as Black_Female
 from employeesl
  group by station,StationID
union all
select 'All Stations',999,
sum(gender='M' and race='W') as White_Male,
sum(gender='F' and race='W') as White_Female,
sum(gender='M' and race='B') as Black_Male,
sum(gender='F' and race='B') as Black_Female
 from employeesl
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jul 2023 11:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-create-a-table-using-frequencies/m-p/884465#M39253</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-07-12T11:39:21Z</dc:date>
    </item>
  </channel>
</rss>

