<?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: Cross tabulation - Frequency Table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766214#M242813</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	value yrfmt
	2013=2013
	2014=2014
	2015=2015
	2016=2016
	2017=2017
	;
	
	value tcfmt
	1=1
	2=2
	3=3
	4=4
	5=5
	6=6
	7=7
	;
run;

proc tabulate data=sample out=counts;
	class FY tc / preloadfmt;
	format tc tcfmt. fy yrfmt.;
	table FY*tc / printmiss;
run;

proc sort data=counts;
	by fy;
run;

proc transpose data=counts out=counts_t (drop=_name_) prefix=tc;
	by fy;
	var N;
	id tc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also do with proc tabulate despite you saying it's against your preference. Preloadfmt allows you to get all possible combinations of TC and FY so that you can get the 0s for TC3. You can output the data from proc tabulate and then sort and transpose it.&lt;/P&gt;</description>
    <pubDate>Mon, 06 Sep 2021 12:49:19 GMT</pubDate>
    <dc:creator>tarheel13</dc:creator>
    <dc:date>2021-09-06T12:49:19Z</dc:date>
    <item>
      <title>Cross tabulation - Frequency Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766169#M242787</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The dataset is:&lt;/P&gt;&lt;P&gt;FY&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TC&lt;/P&gt;&lt;P&gt;2013&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;2014&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;BR /&gt;2013&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;BR /&gt;2015&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;BR /&gt;2016&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;2015&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;BR /&gt;2016&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;2014&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;2013&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;BR /&gt;2014&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;BR /&gt;2017&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;BR /&gt;2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;BR /&gt;2015&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;BR /&gt;2014&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;2015&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63320i4A056AB9929F0795/image-size/medium?v=v2&amp;amp;px=400" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The important point in the above output is that there is no data point for TC=3 but I want it in my output dataset, which I need later for calculation in another step. Again this TC=3 data unavailability is just for depiction only and for one particular category (eg. commercial real estate). For other categories, I might have data points missing for TC=4 (e..g for residential real estate). So I need a cross table where I can have frequency columns for each from TC=1 to TC=7 irrespective of the fact whether any datapoint is available for TC=1 to TC=7 or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am well aware of PROC REPORT but it is not creating tables for TC=3. I think it can be done using PROC SQL. Please help me here. I prefer PROC SQL, PROC REPORT as their output can be used easily in a later step.&lt;/P&gt;&lt;P&gt;Not preferred: PROC TABULATE, PROC FREQ&lt;/P&gt;</description>
      <pubDate>Mon, 06 Sep 2021 07:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766169#M242787</guid>
      <dc:creator>vkabdwal</dc:creator>
      <dc:date>2021-09-06T07:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: Cross tabulation - Frequency Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766201#M242805</link>
      <description>Can you please post the data as data lines?</description>
      <pubDate>Mon, 06 Sep 2021 11:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766201#M242805</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-09-06T11:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: Cross tabulation - Frequency Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766202#M242806</link>
      <description>&lt;P&gt;This can be easily done in SQL with sum.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
input FY TC;
datalines;
2013 1
2014 5
2013 6
2015 7
2016 1
2015 5
2016 2
2014 2
2013 7
2014 4
2017 5
2018 1
2018 6
2015 4
2014 2
2015 4
;
proc print;
run;

proc sql;
	select FY, 
	sum(TC=1) as tc1,
	sum(TC=2) as tc2,
	sum(TC=3) as tc3,
	sum(TC=4) as tc4,
	sum(TC=5) as tc5,
	sum(TC=6) as tc6,
	sum(TC=7) as tc7
		from sample
		group by FY;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Sep 2021 12:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766202#M242806</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-09-06T12:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: Cross tabulation - Frequency Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766209#M242809</link>
      <description>&lt;P&gt;A PROC REPORT solution:&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 sample;
input FY TC;
datalines;
2013 1
2014 5
2013 6
2015 7
2016 1
2015 5
2016 2
2014 2
2013 7
2014 4
2017 5
2018 1
2018 6
2015 4
2014 2
2015 4
;
data intermediate;
    set sample end=eof;
    weight=1;
    output;
    if eof then do;
        tc=3;
        weight=0;
        output;
    end;
run;
options missing=0;
proc report data=intermediate;
    columns fy tc,weight;
    define fy/group;
    define tc/across;
    define weight/sum ' ';
    rbreak after/summarize;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;I prefer PROC SQL, PROC REPORT as their output can be used easily in a later step. Not preferred: PROC TABULATE, PROC FREQ&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;All output from any SAS PROC can be used in a later step.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Sep 2021 12:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766209#M242809</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-06T12:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: Cross tabulation - Frequency Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766212#M242812</link>
      <description>Thank you very much !!&lt;BR /&gt;It is working.</description>
      <pubDate>Mon, 06 Sep 2021 12:42:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766212#M242812</guid>
      <dc:creator>vkabdwal</dc:creator>
      <dc:date>2021-09-06T12:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: Cross tabulation - Frequency Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766214#M242813</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	value yrfmt
	2013=2013
	2014=2014
	2015=2015
	2016=2016
	2017=2017
	;
	
	value tcfmt
	1=1
	2=2
	3=3
	4=4
	5=5
	6=6
	7=7
	;
run;

proc tabulate data=sample out=counts;
	class FY tc / preloadfmt;
	format tc tcfmt. fy yrfmt.;
	table FY*tc / printmiss;
run;

proc sort data=counts;
	by fy;
run;

proc transpose data=counts out=counts_t (drop=_name_) prefix=tc;
	by fy;
	var N;
	id tc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also do with proc tabulate despite you saying it's against your preference. Preloadfmt allows you to get all possible combinations of TC and FY so that you can get the 0s for TC3. You can output the data from proc tabulate and then sort and transpose it.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Sep 2021 12:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766214#M242813</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-09-06T12:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: Cross tabulation - Frequency Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766215#M242814</link>
      <description>Thanks a lot !!&lt;BR /&gt;It is working on SAS OnDemand but surprisingly not giving the desired output (tc=3 missing) in SAS Enterprise 7.15.&lt;BR /&gt;&lt;BR /&gt;But got the idea about the logic you are using.</description>
      <pubDate>Mon, 06 Sep 2021 12:49:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766215#M242814</guid>
      <dc:creator>vkabdwal</dc:creator>
      <dc:date>2021-09-06T12:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: Cross tabulation - Frequency Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766219#M242815</link>
      <description>It is also working. Thanks again.&lt;BR /&gt;PROC SQL is a lot easier to understand and code. I prefer simplicity.</description>
      <pubDate>Mon, 06 Sep 2021 12:58:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-tabulation-Frequency-Table/m-p/766219#M242815</guid>
      <dc:creator>vkabdwal</dc:creator>
      <dc:date>2021-09-06T12:58:31Z</dc:date>
    </item>
  </channel>
</rss>

