<?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: Create condition on one dataset based on another dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-condition-on-one-dataset-based-on-another-dataset/m-p/759762#M240161</link>
    <description>&lt;P&gt;Since your Have set has multiple statistics perhaps you only meant the rows where the N statistic matters?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Combine the Have and Have2 so that there is a NEW variable that has the N. Then use a Where in the model to select appropriate records.&lt;/P&gt;
&lt;P&gt;Not tested code for obvious reasons:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc sort data=have2;
   by bmi;
run;
Proc sort data=have (where=(stat='N')) out=bmin;
   by bmi;
run;

data want;
   merge have2  
              bmin (rename=(stper=stper_n))
   ;
   by bmi;
run; 

Proc glm data=want;
   where stper_n &amp;gt; 3;
   class BMI;
&amp;lt;rest of glm code goes here&amp;gt;
&lt;/PRE&gt;
&lt;P&gt;You might save some minor coding by creating a summary set with only the count and use that instead of Have with all the statistics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Aug 2021 17:17:40 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-08-05T17:17:40Z</dc:date>
    <item>
      <title>Create condition on one dataset based on another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-condition-on-one-dataset-based-on-another-dataset/m-p/759754#M240158</link>
      <description>&lt;P&gt;I have two datasets that look like the following:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mariko5797_0-1628180256340.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62311i2F833459EBC636B8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mariko5797_0-1628180256340.png" alt="mariko5797_0-1628180256340.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I want to perform ANOVA only if there are more than 3 subjects in each BMI category for each time period (STPER, ENDPER). In my head it would be something along the lines of&lt;/P&gt;&lt;PRE&gt;%if have.STPER &amp;gt; 3 (where BMI = 'Not Obese' and STAT = 'N') and have.STPER &amp;gt; 3 (where BMI = 'Not Obese' and STAT = 'N') and have.STPER &amp;gt; 3 (where BMI = 'Not Obese' and STAT = 'N') %then %do;
 proc glm data = have2;
  class BMI;
  model log(CONCEN) = BMI;
  means BMI / hovtest = levene welch;&lt;BR /&gt;  ods output welch = welch diff = pairs;
 run;&lt;BR /&gt;/*repeat for ENDPER*/&lt;/PRE&gt;&lt;P&gt;I have very little experience with macros, so I'm not sure if what I am asking is possible.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 16:42:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-condition-on-one-dataset-based-on-another-dataset/m-p/759754#M240158</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2021-08-05T16:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create condition on one dataset based on another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-condition-on-one-dataset-based-on-another-dataset/m-p/759761#M240160</link>
      <description>&lt;P&gt;You don't need full-blown macro code here.&amp;nbsp; Instead you can use the "select ... into :macrovar" facility of PROC SQL to populate a the macrovar &amp;amp;BMI_LIST with a comma separated list of quoted BMI levels that satisfy your requirements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select quote(strip(bmi)) into :bmi_list separated by ','
  from have
  where stat='N' and stper&amp;gt;3;
quit;
%put &amp;amp;=bmi_list;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then run your PROC GLM code, with the additional where statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc glm data = have2;
  where bmi in (&amp;amp;bmi_list);
  class BMI;
  model log(CONCEN) = BMI;
  means BMI / hovtest = levene welch;
  ods output welch = welch diff = pairs;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, you'd have to run this twice, once for STPER and once for ENDPER.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 17:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-condition-on-one-dataset-based-on-another-dataset/m-p/759761#M240160</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-08-05T17:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: Create condition on one dataset based on another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-condition-on-one-dataset-based-on-another-dataset/m-p/759762#M240161</link>
      <description>&lt;P&gt;Since your Have set has multiple statistics perhaps you only meant the rows where the N statistic matters?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Combine the Have and Have2 so that there is a NEW variable that has the N. Then use a Where in the model to select appropriate records.&lt;/P&gt;
&lt;P&gt;Not tested code for obvious reasons:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc sort data=have2;
   by bmi;
run;
Proc sort data=have (where=(stat='N')) out=bmin;
   by bmi;
run;

data want;
   merge have2  
              bmin (rename=(stper=stper_n))
   ;
   by bmi;
run; 

Proc glm data=want;
   where stper_n &amp;gt; 3;
   class BMI;
&amp;lt;rest of glm code goes here&amp;gt;
&lt;/PRE&gt;
&lt;P&gt;You might save some minor coding by creating a summary set with only the count and use that instead of Have with all the statistics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 17:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-condition-on-one-dataset-based-on-another-dataset/m-p/759762#M240161</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-05T17:17:40Z</dc:date>
    </item>
  </channel>
</rss>

