<?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 How do I create a new variable using an if then statement for above median and below median value? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-new-variable-using-an-if-then-statement-for/m-p/893371#M353391</link>
    <description />
    <pubDate>Fri, 08 Sep 2023 16:44:04 GMT</pubDate>
    <dc:creator>SAS_Cares</dc:creator>
    <dc:date>2023-09-08T16:44:04Z</dc:date>
    <item>
      <title>How do I create a new variable using an if then statement for above median and below median value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-new-variable-using-an-if-then-statement-for/m-p/893339#M352916</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I create a new variable using an if then statement for above median and below median roi value? I want to create a new column using data syntax, that will show value 1 for ROIs above median roi, otherwise 0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I got to this point below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87720i68098FD4469D7394/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 16:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-new-variable-using-an-if-then-statement-for/m-p/893339#M352916</guid>
      <dc:creator>prn21005</dc:creator>
      <dc:date>2023-09-08T16:44:04Z</dc:date>
    </item>
    <item>
      <title>How do I create a new variable using an if then statement for above median and below median value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-new-variable-using-an-if-then-statement-for/m-p/893371#M353391</link>
      <description />
      <pubDate>Fri, 08 Sep 2023 16:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-new-variable-using-an-if-then-statement-for/m-p/893371#M353391</guid>
      <dc:creator>SAS_Cares</dc:creator>
      <dc:date>2023-09-08T16:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new variable using an if then statement for above median and below median valu</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-new-variable-using-an-if-then-statement-for/m-p/893376#M352918</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Welcome to the Communities forum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I've understood your requirements correctly, does the following help (essentially the last step creates the new column, the rest is just set up):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* set up sample roi data */
data have;
  input roi;
  
  datalines;
 1
 2
 3
 4
 5
 ;
 
 
 /* set up median roi value */
 %let median_roi = 3;
 
 
 data want;
   set have;
   
   /* use greater than comparison operator to assign 1 (true) or 0 (false) */
   new_column = roi gt &amp;amp;median_roi;
 run;
&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;If you need something different, then please show what results you are looking for for each row and confirm the logic behind it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 19:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-new-variable-using-an-if-then-statement-for/m-p/893376#M352918</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2023-09-08T19:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new variable using an if then statement for above median and below median valu</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-new-variable-using-an-if-then-statement-for/m-p/893382#M352919</link>
      <description>&lt;P&gt;Use PROC RANK and 2 ranks to split the data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 20:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-new-variable-using-an-if-then-statement-for/m-p/893382#M352919</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-09-08T20:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new variable using an if then statement for above median and below median valu</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-new-variable-using-an-if-then-statement-for/m-p/893389#M352922</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=modtwo out=want groups=2 ties=low;
var roi;
ranks rankROI;
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/451773"&gt;@prn21005&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I create a new variable using an if then statement for above median and below median roi value? I want to create a new column using data syntax, that will show value 1 for ROIs above median roi, otherwise 0.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So far I got to this point below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87720i68098FD4469D7394/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&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;</description>
      <pubDate>Fri, 08 Sep 2023 21:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-new-variable-using-an-if-then-statement-for/m-p/893389#M352922</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-09-08T21:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new variable using an if then statement for above median and below median valu</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-new-variable-using-an-if-then-statement-for/m-p/893407#M352929</link>
      <description>&lt;P&gt;First, realize that you will eventually need to deal with realistic questions.&amp;nbsp; What should happen with ROI:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Is exactly equal to the median?&lt;/LI&gt;
&lt;LI&gt;Has a missing value?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Here is an approach that extends tools that you already know, to get the result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
   var roi;
   output out=medians (keep=roi_median) median=roi_median;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That gives you the median in a data set, which can be used in a subsequent step.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   if _n_=1 then set medians;
   roi_group = roi &amp;gt;= roi_median;
   drop roi_median;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the logic can easily be expanded to compute/group for more than one variable, without increasing the number of steps.&amp;nbsp; For example, you could begin with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
   var roi margin turnover;
   output out=medians (keep=roi_median margin_median turnover_median) median=roi_median margin_median turnover_median;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Also note that the assignment statement that computes roi_group could have been accomplished with IF/THEN statements, but would take more code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if roi &amp;gt;= roi_median then roi_group=1;
else roi_group = 0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the assignment statement shown above accomplishes the same with a shorter program.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2023 01:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-new-variable-using-an-if-then-statement-for/m-p/893407#M352929</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-09-09T01:13:05Z</dc:date>
    </item>
  </channel>
</rss>

