<?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: Creating a loop for chisquare analysis in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591256#M15166</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc surveyfreq data=xx;
    weight wt;
    strata strata;
    cluster cluster;
    tables y*(x1-x16) / chisq;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Syntax correction. (Don't use "=" in WEIGHT, STRATA, and CLUSTER statements.)&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Sep 2019 18:27:08 GMT</pubDate>
    <dc:creator>Watts</dc:creator>
    <dc:date>2019-09-24T18:27:08Z</dc:date>
    <item>
      <title>Creating a loop for chisquare analysis</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591233#M15159</link>
      <description>&lt;P&gt;Good day everyone.&lt;/P&gt;&lt;P&gt;I am new to loops and macros.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have the task of running chi-square statistics on a series of sixteen variables&lt;/P&gt;&lt;P&gt;I feel I can get a more parsimonious SAS code by using loops and/or macros.&lt;/P&gt;&lt;P&gt;I have a series of variable X1 to X16 to run against y.&lt;/P&gt;&lt;P&gt;Please kindly assist.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc surveyfreq data=xx;
weight = wt;
strata = strata;
cluster = cluster;
tables y*x1 / chisq;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Sep 2019 17:20:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591233#M15159</guid>
      <dc:creator>oadeyemi</dc:creator>
      <dc:date>2019-09-24T17:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a loop for chisquare analysis</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591236#M15160</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc surveyfreq data=xx;
weight = wt;
strata = strata;
cluster = cluster;
tables y*(x1-x16) / chisq;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does that give you what you want?&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/283068"&gt;@oadeyemi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Good day everyone.&lt;/P&gt;
&lt;P&gt;I am new to loops and macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have the task of running chi-square statistics on a series of sixteen variables&lt;/P&gt;
&lt;P&gt;I feel I can get a more parsimonious SAS code by using loops and/or macros.&lt;/P&gt;
&lt;P&gt;I have a series of variable X1 to X16 to run against y.&lt;/P&gt;
&lt;P&gt;Please kindly assist.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc surveyfreq data=xx;
weight = wt;
strata = strata;
cluster = cluster;
tables y*x1 / chisq;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 17:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591236#M15160</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-24T17:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a loop for chisquare analysis</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591240#M15161</link>
      <description>&lt;P&gt;Thank you for the response.&lt;/P&gt;&lt;P&gt;Yes, that can work too.&lt;/P&gt;&lt;P&gt;But x1 to x16 are long variable names.&lt;/P&gt;&lt;P&gt;I am thinking of pooling them in a local macro and use the macro for the step.&lt;/P&gt;&lt;P&gt;Do you understand my thought? Would it be more parsimonious?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like this....(note: this is not SAS format)&lt;/P&gt;&lt;P&gt;local a x1 x2 x3 x4 x5...x16&lt;/P&gt;&lt;P&gt;For each `var' in a....&lt;/P&gt;&lt;P&gt;....and I plug in a at&amp;nbsp;&lt;/P&gt;&lt;P&gt;tables y*`a'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 17:35:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591240#M15161</guid>
      <dc:creator>oadeyemi</dc:creator>
      <dc:date>2019-09-24T17:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a loop for chisquare analysis</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591242#M15162</link>
      <description>&lt;P&gt;No, it would not be more parsimonious, in fact it's more verbose.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use Variable Lists of some form instead.&lt;/P&gt;
&lt;P&gt;If you have a common prefix, or the variables are side by side this is easy.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not, and you list the variables in a local macro variable then you would just replace my x1-x16 with the macro variable instead. And that would still be more typing and characters so again, more verbose. The solution above is the most parsimonious solution, if that's your goal.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Various methods to list variables are included here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The method you've mentioned would not be parsimonious in either R or Python, there are easier ways in those languages as well.&amp;nbsp;&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/283068"&gt;@oadeyemi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for the response.&lt;/P&gt;
&lt;P&gt;Yes, that can work too.&lt;/P&gt;
&lt;P&gt;But x1 to x16 are long variable names.&lt;/P&gt;
&lt;P&gt;I am thinking of pooling them in a local macro and use the macro for the step.&lt;/P&gt;
&lt;P&gt;Do you understand my thought? Would it be more parsimonious?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this....(note: this is not SAS format)&lt;/P&gt;
&lt;P&gt;local a x1 x2 x3 x4 x5...x16&lt;/P&gt;
&lt;P&gt;For each `var' in a....&lt;/P&gt;
&lt;P&gt;....and I plug in a at&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tables y*`a'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 17:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591242#M15162</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-24T17:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a loop for chisquare analysis</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591245#M15163</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/283068"&gt;@oadeyemi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for the response.&lt;/P&gt;
&lt;P&gt;Yes, that can work too.&lt;/P&gt;
&lt;P&gt;But x1 to x16 are long variable names.&lt;/P&gt;
&lt;P&gt;I am thinking of pooling them in a local macro and use the macro for the step.&lt;/P&gt;
&lt;P&gt;Do you understand my thought? Would it be more parsimonious?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this....(note: this is not SAS format)&lt;/P&gt;
&lt;P&gt;local a x1 x2 x3 x4 x5...x16&lt;/P&gt;
&lt;P&gt;For each `var' in a....&lt;/P&gt;
&lt;P&gt;....and I plug in a at&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tables y*`a'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Typing the list of variables into a macro variable, or typing the list of variables into the PROC SURVEYSELECT as suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;, is equal amount of effort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Getting a macro to work that does the looping is extra work that doesn't exist if you use PROC SURVEYSELECT as Reeza showed. I don't see what you gain by a macro.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 18:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591245#M15163</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-24T18:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a loop for chisquare analysis</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591250#M15164</link>
      <description>&lt;P&gt;I agree with you.&lt;/P&gt;&lt;P&gt;Thanks for your explanation.&lt;/P&gt;&lt;P&gt;Thanks for sharing the link too.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 18:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591250#M15164</guid>
      <dc:creator>oadeyemi</dc:creator>
      <dc:date>2019-09-24T18:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a loop for chisquare analysis</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591251#M15165</link>
      <description>&lt;P&gt;I agree with you.&lt;/P&gt;&lt;P&gt;Thank you for your explanation.&lt;/P&gt;&lt;P&gt;The goal is to be as parsimonious as possible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 18:15:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591251#M15165</guid>
      <dc:creator>oadeyemi</dc:creator>
      <dc:date>2019-09-24T18:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a loop for chisquare analysis</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591256#M15166</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc surveyfreq data=xx;
    weight wt;
    strata strata;
    cluster cluster;
    tables y*(x1-x16) / chisq;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Syntax correction. (Don't use "=" in WEIGHT, STRATA, and CLUSTER statements.)&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 18:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-loop-for-chisquare-analysis/m-p/591256#M15166</guid>
      <dc:creator>Watts</dc:creator>
      <dc:date>2019-09-24T18:27:08Z</dc:date>
    </item>
  </channel>
</rss>

