<?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 a new variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable/m-p/846427#M36886</link>
    <description>&lt;P&gt;haven't seen your data but you should do this check anyway:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tarheel13_0-1669485957708.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77732iB4018232F329B0E2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tarheel13_0-1669485957708.png" alt="tarheel13_0-1669485957708.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bmi;
   set prac.chol_new;
   if nmiss(ht,wt)=0 then do;
      bmi=703*(wt/(ht**2));
   end;
   
   if nmiss(age,bmi)=0 then do;
      if age le 65 then do;
         if bmi &amp;lt; 18 or bmi &amp;gt; 25 then age_bmicat=1;
         else age_bmicat=2;
      end;
      else do;
         if bmi &amp;lt; 25 or bmi &amp;gt; 30 then age_bmicat=3;
         else age_bmicat=4;
      end;
   end;
run;

proc means data=bmi n nmiss min max;
   class age_bmicat / missing;
   var age bmi;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note, it is important to only create the new categorical variable when age and BMI are both nonmissing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 26 Nov 2022 18:06:53 GMT</pubDate>
    <dc:creator>tarheel13</dc:creator>
    <dc:date>2022-11-26T18:06:53Z</dc:date>
    <item>
      <title>Create a new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable/m-p/846037#M36851</link>
      <description>&lt;P&gt;I am new to SAS. I am trying to figure out the best way to create a new variable with the following directions:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Create a new variable called age_bmicat according to the specifications in the table below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-11-23 at 4.15.46 PM.png" style="width: 820px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77643i809522C09F88975B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2022-11-23 at 4.15.46 PM.png" alt="Screen Shot 2022-11-23 at 4.15.46 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 21:16:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable/m-p/846037#M36851</guid>
      <dc:creator>MisterJenn</dc:creator>
      <dc:date>2022-11-23T21:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable/m-p/846044#M36852</link>
      <description>&lt;P&gt;In a SAS data step&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if age&amp;lt;=65 and (bmi&amp;lt;18 or bmi&amp;gt;25) then age_bmicat=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using that as an example, see if you can figure out the code for the rest of the problem.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 22:46:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable/m-p/846044#M36852</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-23T22:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable/m-p/846045#M36853</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

if age &amp;lt;= 65 then do;
    if  18 &amp;lt;= bmi &amp;lt;= 25 then age_bmicat = 2;
    else if age_bmicat &amp;lt; 18 or age_bmicat &amp;gt; 25 = 1;
end;
else if age &amp;gt; 65 then do;
    if  25 &amp;lt;= bmi &amp;lt;= 30 then age_bmicat =  4;
     else if age_bmicat &amp;lt; 25 or age_bmicat &amp;gt; 30 = 3;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/435394"&gt;@MisterJenn&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am new to SAS. I am trying to figure out the best way to create a new variable with the following directions:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a new variable called age_bmicat according to the specifications in the table below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-11-23 at 4.15.46 PM.png" style="width: 820px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77643i809522C09F88975B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2022-11-23 at 4.15.46 PM.png" alt="Screen Shot 2022-11-23 at 4.15.46 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 22:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable/m-p/846045#M36853</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-11-23T22:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable/m-p/846427#M36886</link>
      <description>&lt;P&gt;haven't seen your data but you should do this check anyway:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tarheel13_0-1669485957708.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77732iB4018232F329B0E2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tarheel13_0-1669485957708.png" alt="tarheel13_0-1669485957708.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bmi;
   set prac.chol_new;
   if nmiss(ht,wt)=0 then do;
      bmi=703*(wt/(ht**2));
   end;
   
   if nmiss(age,bmi)=0 then do;
      if age le 65 then do;
         if bmi &amp;lt; 18 or bmi &amp;gt; 25 then age_bmicat=1;
         else age_bmicat=2;
      end;
      else do;
         if bmi &amp;lt; 25 or bmi &amp;gt; 30 then age_bmicat=3;
         else age_bmicat=4;
      end;
   end;
run;

proc means data=bmi n nmiss min max;
   class age_bmicat / missing;
   var age bmi;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note, it is important to only create the new categorical variable when age and BMI are both nonmissing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2022 18:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable/m-p/846427#M36886</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-11-26T18:06:53Z</dc:date>
    </item>
  </channel>
</rss>

