<?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 to arrange data in rows and columns when inputting when you only have totals? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-arrange-data-in-rows-and-columns-when-inputting-when-you/m-p/781394#M31767</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA ASPIRIN; 
   INPUT Treat $ Total CVD Divided; 
   DATALINES; 
   1=Aspirin 19934 477 .0239
   2=Placebo 19942 522 .0262
;
run;

data aspirin_long;
set aspirin;
treatment = input(scan(treat, 1, "="), 8.);
Disease=1;
N=CVD;
output;
Disease=0;
N=Total-CVD;
output;
run;

proc format;
value treat_fmt
1 = 'Aspirin'
2 = 'Placebo'
;
value disease_fmt
1 = 'CVD'
0 = 'Non-CVD';
run;

proc freq data=aspirin_long;
table treatment*disease;
weight N;
format treatment treat_fmt. disease disease_fmt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use the WEIGHT statement to use aggregate data but you do need to have the data structured a bit differently.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hopefully this works for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/396363"&gt;@akimme&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone, I'm trying to:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;run a chi square on proportions of people who did and did not have a cardiovascular (CVD) event, comparing those who did and did not take aspirin&lt;/LI&gt;
&lt;LI&gt;and determine if a positive result on one test vs another are associated&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;I've tried a few ways to arrange the rows and columns, but none of them produce any kind of useful output from PROC FREQ (see spoiler). I only have the totals: I don't have a file with all 19934 lines of data, just the information that 477 of them had a CVD. Is there any way to use SAS for this calculation, short of inputting 40,000 lines of data?&lt;/P&gt;
&lt;LI-SPOILER&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="useless.PNG" style="width: 320px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65940i00F5B0B14C0E2E60/image-size/large?v=v2&amp;amp;px=999" role="button" title="useless.PNG" alt="useless.PNG" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="useless2.PNG" style="width: 337px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65941i751E61B1235E0250/image-size/large?v=v2&amp;amp;px=999" role="button" title="useless2.PNG" alt="useless2.PNG" /&gt;&lt;/span&gt;&lt;/LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;DATA ASPIRIN; 
   INPUT Treat $ Total CVD Divided; 
   DATALINES; 
   1=Aspirin 19934 477 .0239
   2=Placebo 19942 522 .0262
;
run;

PROC FREQ DATA=ASPIRIN;
TABLES Total*CVD /CHISQ RELRISK ;
TITLE 'Relationship between treatment and CVD';
RUN;

DATA TEST; 
   INPUT Q $ Yes; &lt;BR /&gt;*I initially also tried &lt;BR /&gt;putting in 4 variables (Q1andQ2, etc) &lt;BR /&gt;with 1 value each but this also seemed not to work? &lt;BR /&gt;What am I missing?;
   DATALINES; 
Q1andQ2 172 
NEITHER 15  
OnlyQ1 7    
OnlyQ2 6   
;
run;

PROC freq data = test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you!!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 Nov 2021 21:34:49 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-11-19T21:34:49Z</dc:date>
    <item>
      <title>How to arrange data in rows and columns when inputting when you only have totals?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-arrange-data-in-rows-and-columns-when-inputting-when-you/m-p/781390#M31765</link>
      <description>&lt;P&gt;Hi everyone, I'm trying to:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;run a chi square on proportions of people who did and did not have a cardiovascular (CVD) event, comparing those who did and did not take aspirin&lt;/LI&gt;&lt;LI&gt;and determine if a positive result on one test vs another are associated&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I've tried a few ways to arrange the rows and columns, but none of them produce any kind of useful output from PROC FREQ (see spoiler). I only have the totals: I don't have a file with all 19934 lines of data, just the information that 477 of them had a CVD. Is there any way to use SAS for this calculation, short of inputting 40,000 lines of data?&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="useless.PNG" style="width: 320px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65940i00F5B0B14C0E2E60/image-size/large?v=v2&amp;amp;px=999" role="button" title="useless.PNG" alt="useless.PNG" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="useless2.PNG" style="width: 337px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65941i751E61B1235E0250/image-size/large?v=v2&amp;amp;px=999" role="button" title="useless2.PNG" alt="useless2.PNG" /&gt;&lt;/span&gt;&lt;/LI-SPOILER&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA ASPIRIN; 
   INPUT Treat $ Total CVD Divided; 
   DATALINES; 
   1=Aspirin 19934 477 .0239
   2=Placebo 19942 522 .0262
;
run;

PROC FREQ DATA=ASPIRIN;
TABLES Total*CVD /CHISQ RELRISK ;
TITLE 'Relationship between treatment and CVD';
RUN;

DATA TEST; 
   INPUT Q $ Yes; &lt;BR /&gt;*I initially also tried &lt;BR /&gt;putting in 4 variables (Q1andQ2, etc) &lt;BR /&gt;with 1 value each but this also seemed not to work? &lt;BR /&gt;What am I missing?;
   DATALINES; 
Q1andQ2 172 
NEITHER 15  
OnlyQ1 7    
OnlyQ2 6   
;
run;

PROC freq data = test;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you!!&lt;/P&gt;</description>
      <pubDate>Fri, 19 Nov 2021 21:10:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-arrange-data-in-rows-and-columns-when-inputting-when-you/m-p/781390#M31765</guid>
      <dc:creator>akimme</dc:creator>
      <dc:date>2021-11-19T21:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange data in rows and columns when inputting when you only have totals?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-arrange-data-in-rows-and-columns-when-inputting-when-you/m-p/781394#M31767</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA ASPIRIN; 
   INPUT Treat $ Total CVD Divided; 
   DATALINES; 
   1=Aspirin 19934 477 .0239
   2=Placebo 19942 522 .0262
;
run;

data aspirin_long;
set aspirin;
treatment = input(scan(treat, 1, "="), 8.);
Disease=1;
N=CVD;
output;
Disease=0;
N=Total-CVD;
output;
run;

proc format;
value treat_fmt
1 = 'Aspirin'
2 = 'Placebo'
;
value disease_fmt
1 = 'CVD'
0 = 'Non-CVD';
run;

proc freq data=aspirin_long;
table treatment*disease;
weight N;
format treatment treat_fmt. disease disease_fmt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use the WEIGHT statement to use aggregate data but you do need to have the data structured a bit differently.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hopefully this works for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/396363"&gt;@akimme&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone, I'm trying to:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;run a chi square on proportions of people who did and did not have a cardiovascular (CVD) event, comparing those who did and did not take aspirin&lt;/LI&gt;
&lt;LI&gt;and determine if a positive result on one test vs another are associated&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;I've tried a few ways to arrange the rows and columns, but none of them produce any kind of useful output from PROC FREQ (see spoiler). I only have the totals: I don't have a file with all 19934 lines of data, just the information that 477 of them had a CVD. Is there any way to use SAS for this calculation, short of inputting 40,000 lines of data?&lt;/P&gt;
&lt;LI-SPOILER&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="useless.PNG" style="width: 320px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65940i00F5B0B14C0E2E60/image-size/large?v=v2&amp;amp;px=999" role="button" title="useless.PNG" alt="useless.PNG" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="useless2.PNG" style="width: 337px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65941i751E61B1235E0250/image-size/large?v=v2&amp;amp;px=999" role="button" title="useless2.PNG" alt="useless2.PNG" /&gt;&lt;/span&gt;&lt;/LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;DATA ASPIRIN; 
   INPUT Treat $ Total CVD Divided; 
   DATALINES; 
   1=Aspirin 19934 477 .0239
   2=Placebo 19942 522 .0262
;
run;

PROC FREQ DATA=ASPIRIN;
TABLES Total*CVD /CHISQ RELRISK ;
TITLE 'Relationship between treatment and CVD';
RUN;

DATA TEST; 
   INPUT Q $ Yes; &lt;BR /&gt;*I initially also tried &lt;BR /&gt;putting in 4 variables (Q1andQ2, etc) &lt;BR /&gt;with 1 value each but this also seemed not to work? &lt;BR /&gt;What am I missing?;
   DATALINES; 
Q1andQ2 172 
NEITHER 15  
OnlyQ1 7    
OnlyQ2 6   
;
run;

PROC freq data = test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you!!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Nov 2021 21:34:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-arrange-data-in-rows-and-columns-when-inputting-when-you/m-p/781394#M31767</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-11-19T21:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange data in rows and columns when inputting when you only have totals?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-arrange-data-in-rows-and-columns-when-inputting-when-you/m-p/781427#M31777</link>
      <description>&lt;P&gt;You need N*M observations to represent data when have two factors that have N and M possible values.&lt;/P&gt;
&lt;P&gt;So you need 2*2=4 observations.&lt;/P&gt;
&lt;P&gt;You can get it from your source text.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA ASPIRIN; 
   INPUT Treat :$20. Total CVD Divided;
   HAS_CVD=1;
   COUNT=CVD;
   output;
   HAS_CVD=0;
   count = total-cvd;
   output;
   keep treat has_cvd count; 
DATALINES; 
1=Aspirin 19934 477 .0239
2=Placebo 19942 522 .0262
;

proc print;
run;

proc freq ;
  tables treat*has_cvd /chisq;
  weight count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 413px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65948i4BFE514D88099DBC/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;The FREQ Procedure

Statistics for Table of Treat by HAS_CVD

Statistic                     DF       Value      Prob
------------------------------------------------------
Chi-Square                     1      2.0606    0.1511
Likelihood Ratio Chi-Square    1      2.0613    0.1511
Continuity Adj. Chi-Square     1      1.9697    0.1605
Mantel-Haenszel Chi-Square     1      2.0606    0.1512
Phi Coefficient                       0.0072
Contingency Coefficient               0.0072
Cramer's V                            0.0072


       Fisher's Exact Test
----------------------------------
Cell (1,1) Frequency (F)     19457
Left-sided Pr &amp;lt;= F          0.9289
Right-sided Pr &amp;gt;= F         0.0802

Table Probability (P)       0.0091
Two-sided Pr &amp;lt;= P           0.1586

Sample Size = 39876
&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Nov 2021 04:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-arrange-data-in-rows-and-columns-when-inputting-when-you/m-p/781427#M31777</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-20T04:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange data in rows and columns when inputting when you only have totals?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-arrange-data-in-rows-and-columns-when-inputting-when-you/m-p/781510#M31805</link>
      <description>&lt;P&gt;Okay, it looks like the COUNT= step was the big thing I was missing. That worked, thank you so much!&lt;/P&gt;</description>
      <pubDate>Sun, 21 Nov 2021 04:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-arrange-data-in-rows-and-columns-when-inputting-when-you/m-p/781510#M31805</guid>
      <dc:creator>akimme</dc:creator>
      <dc:date>2021-11-21T04:25:26Z</dc:date>
    </item>
  </channel>
</rss>

