<?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: Automation Cross Tabulation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Automation-Cross-Tabulation/m-p/442137#M282698</link>
    <description>&lt;P&gt;Had to guess what variable d actually is in your data... You seem to need something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile "&amp;amp;sasforum\datasets\wiedat2b.csv" firstobs=2 dsd;
input y1 y2 kyphosis;
run;

proc sql;
create table temp as
select distinct
    a.y1 as compare_y1,
    b.*,
    a.y1 &amp;lt; b.y1 as beta
from have as a, have as b
order by compare_y1, y1;
quit;

proc freq data=temp noprint;
by compare_y1;
table beta*kyphosis / chisq;
output out=myChisq chisq;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;replace chisq with whatever table statistic you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 04 Mar 2018 06:05:22 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2018-03-04T06:05:22Z</dc:date>
    <item>
      <title>Automation Cross Tabulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automation-Cross-Tabulation/m-p/442135#M282697</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have continue variable y1. I need to create a binary variable from it using the first observation of y1. Then tabulate the created binary variable with the variable d in the attached dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to re[eat this process for all observations of&amp;nbsp; of y1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have written SAS codes below and was wondering if you can help to modify it so that I have different cross tabulate tables for each observation of y1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is my SAS codes:&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;** I have dataset "wiedat2b" and ordering it by variable order;&lt;BR /&gt;data want;&lt;BR /&gt;set &lt;SPAN&gt;wiedat2b&lt;/SPAN&gt;;&lt;BR /&gt;by y1;&lt;BR /&gt;retain order 0;&lt;BR /&gt;if first.y1 then order=order+1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;** then create binary variable beta and tabulate the results;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA want;&lt;BR /&gt;set want;&lt;BR /&gt;** Need Create a binary variable;&lt;BR /&gt;if y1 &amp;lt;=2.4 then beta2=0; * 2.4 is the FIRST observation of y1;&lt;BR /&gt;else beta1=1;&lt;BR /&gt;proc freq data = want order = formatted;&lt;BR /&gt;tables d * beta / nocol nopercent;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;** then create binary variable 2 and tabuate the results;&lt;BR /&gt;DATA want;&lt;BR /&gt;set want;&lt;BR /&gt;** Need Create a binary variable;&lt;BR /&gt;if y1 &amp;lt;=3.4 then beta2=0; * 3.4 is the SECOND obsrvation of y1;&lt;BR /&gt;else beta2=1;&lt;BR /&gt;proc freq data = want order = formatted;&lt;BR /&gt;tables d * y11 / nocol nopercent;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;**HOW TO REPEAT THIS PROCESS FOR EACH OBSERVATION OF y1 and tabulate the results?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Mar 2018 05:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automation-Cross-Tabulation/m-p/442135#M282697</guid>
      <dc:creator>jeka1212</dc:creator>
      <dc:date>2018-03-04T05:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: Automation Cross Tabulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automation-Cross-Tabulation/m-p/442137#M282698</link>
      <description>&lt;P&gt;Had to guess what variable d actually is in your data... You seem to need something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile "&amp;amp;sasforum\datasets\wiedat2b.csv" firstobs=2 dsd;
input y1 y2 kyphosis;
run;

proc sql;
create table temp as
select distinct
    a.y1 as compare_y1,
    b.*,
    a.y1 &amp;lt; b.y1 as beta
from have as a, have as b
order by compare_y1, y1;
quit;

proc freq data=temp noprint;
by compare_y1;
table beta*kyphosis / chisq;
output out=myChisq chisq;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;replace chisq with whatever table statistic you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Mar 2018 06:05:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automation-Cross-Tabulation/m-p/442137#M282698</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-03-04T06:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Automation Cross Tabulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automation-Cross-Tabulation/m-p/442150#M282699</link>
      <description>&lt;P&gt;Many Thanks. I have what i wanted using the modified codes&amp;nbsp; below. I have attached a sample of the output from SAS&amp;nbsp; and was wondering if you can help to select some results in a transpose table. Many thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
infile "&amp;amp;sasforum\datasets\wiedat2b.csv" firstobs=2 dsd;
input y1 y2 kyphosis;
run;

proc sql;
create table temp as
select distinct
    a.y1 as compare_y1,
    b.*,
    a.y1 &amp;lt; b.y1 as beta
from have as a, have as b
order by compare_y1, y1;
quit;

proc sort data=temp;
         by descending beta descending kyphosis;
         run;

proc freq data = temp order=data noprint ;
by compare_y1;
            tables  beta*kyphosis / out=FreqCount OUTPCT sparse ;
			*output out=mnocol;
run;

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Mar 2018 15:26:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automation-Cross-Tabulation/m-p/442150#M282699</guid>
      <dc:creator>jeka1212</dc:creator>
      <dc:date>2018-03-04T15:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: Automation Cross Tabulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automation-Cross-Tabulation/m-p/442231#M282700</link>
      <description>&lt;P&gt;Try something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data freqTable;
merge 
    freqCount (
        keep=compare_y1 beta kyphosis count 
        rename=(count=falpos) 
        where=(beta=0 and kyphosis=1))
    freqCount (
        keep=compare_y1 beta kyphosis count 
        rename=(count=falneg) 
        where=(beta=1 and kyphosis=0))
    freqCount (
        keep=compare_y1 beta kyphosis count pct_row pct_col
        rename=(count=neg pct_row=npv pct_col=specif) 
        where=(beta=0 and kyphosis=0))
    freqCount (
        keep=compare_y1 beta kyphosis count pct_row pct_col
        rename=(count=pos pct_row=ppv pct_col=sensit) 
        where=(beta=1 and kyphosis=1));
by compare_y1;
run;

proc print data=freqTable noobs; 
var compare_y1 pos neg falpos falneg sensit specif npv ppv; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Mar 2018 03:22:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automation-Cross-Tabulation/m-p/442231#M282700</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-03-05T03:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: Automation Cross Tabulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automation-Cross-Tabulation/m-p/442240#M282701</link>
      <description>Many thanks PGStats. I am so grateful with your help. Many thanks also for you time.</description>
      <pubDate>Mon, 05 Mar 2018 04:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automation-Cross-Tabulation/m-p/442240#M282701</guid>
      <dc:creator>jeka1212</dc:creator>
      <dc:date>2018-03-05T04:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Automation Cross Tabulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automation-Cross-Tabulation/m-p/443101#M282702</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462" target="_self"&gt;PGStats&lt;/A&gt;&amp;nbsp;and all,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;I need to modify the codes above to create a combined binary variable beta1_beta2&amp;nbsp; with y1 and y2 this time.&amp;nbsp; I was wondering if you can advise me how to modify the previous SAS codes&amp;nbsp; please?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile "&amp;amp;sasforum\datasets\wiedat2b.csv" firstobs=2 dsd;
input y1 y2 kyphosis;
run;

DATA have;
set have;

********Creating the first binary variable beta1 with y1=28;
if y1 &amp;lt;= 28 then beta1=0;
else beta1=1; 

**Creating the first binary variable beta2 with y2=13.3;
if y2 &amp;lt;=13.3 then beta2=0;
else beta2=1;

********Creating the first  combined binary variable beta1_beta2 with the pair (y1=28,y2=13.3);

if beta1=1 &amp;amp; beta2=1 then beta1_beta2=1;
if beta1=1 &amp;amp; beta2=0 then beta1_beta2=1;
if beta1=0 &amp;amp; beta2=1 then beta1_beta2=1;
if beta1=0 &amp;amp; beta2=0 then beta1_beta2=0;
run;

proc freq data = have order=data noprint ;
            tables  beta1_beta2*kyphosis / out=FreqCount OUTPCT sparse ;
		*output out=mnocol;
run;

*THEN REPEAT  FOR:  y1=28, y2=11.1, 12.6, ect...; 

***Do the same for the second paire y1=28,y2=11.1;
***Do the same for the second paire y1=28,y2=12.6;
**........;
***Do the same for the last (141) paire y1=28,y2=14.2;


**THEN REPEAT FOR: y1=16.7, y2=11.1, 12.6, ect...; 

***Do the same for the second paire y1=16.7,y2=11.1;
***Do the same for the second paire y1=16.7,y2=12.6;
**........;
***Do the same for the last (141) paire y1=16.7,y2=14.2;

****HOW TO REPEAT THIS FROCESS FOR ALL 19881 COMBINATION IN THE DATASET (141 X 141 POSSIBLE COMBINATIONS)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 00:03:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automation-Cross-Tabulation/m-p/443101#M282702</guid>
      <dc:creator>jeka1212</dc:creator>
      <dc:date>2018-03-07T00:03:13Z</dc:date>
    </item>
  </channel>
</rss>

