<?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 SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606034#M175935</link>
    <description>&lt;P&gt;DATA T;&lt;BR /&gt;SET FULL;&lt;BR /&gt;if 15 &amp;lt;= dd &amp;lt; 10 then t=-3;&lt;BR /&gt;else if 10 &amp;lt;= dd &amp;lt; 5 then t=-2;&lt;BR /&gt;else if 5 &amp;lt;= dd &amp;lt; 0 then t=-1;&lt;BR /&gt;else if 0 &amp;lt;= dd &amp;lt; -5 then t= 1;&lt;BR /&gt;else if -5 &amp;lt;= dd &amp;lt; -10 then t= 2;&lt;BR /&gt;else if -10 &amp;lt;= dd &amp;lt; -15 then t= 3;&lt;BR /&gt;else if -15 &amp;lt;= dd &amp;lt; -20 then t= 4;&lt;BR /&gt;else if -20 &amp;lt;= dd &amp;lt; -25 then t= 5;&lt;BR /&gt;else if -25 &amp;lt;= dd &amp;lt; -30 then t= 6;&lt;BR /&gt;else if -30 &amp;lt;= dd &amp;lt; -35 then t= 7;&lt;BR /&gt;else if -35 &amp;lt;= dd &amp;lt; -40 then t= 8;&lt;BR /&gt;else if -40 &amp;lt;= dd &amp;lt; -45 then t= 9;&lt;BR /&gt;else if -45 &amp;lt;= dd &amp;lt; -50 then t= 10;&lt;BR /&gt;else if -50 &amp;lt;= dd &amp;lt; -55 then t= 11;&lt;BR /&gt;else if -55 &amp;lt;= dd &amp;lt; -60 then t= 12;&lt;BR /&gt;else if -60 &amp;lt;= dd &amp;lt; -65 then t= 13;&lt;BR /&gt;else if -65 &amp;lt;= dd &amp;lt; -70 then t= 14;&lt;BR /&gt;else if -70 &amp;lt;= dd &amp;lt; -75 then t= 15;&lt;BR /&gt;else if -75 &amp;lt;= dd &amp;lt; -80 then t= 16;&lt;BR /&gt;else if -80 &amp;lt;= dd &amp;lt; -85 then t= 17;&lt;BR /&gt;else if -85 &amp;lt;= dd &amp;lt; -90 then t= 18;&lt;BR /&gt;else t=.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I tried this code, not work.&lt;/P&gt;&lt;P&gt;DD is from -90 to 15&lt;/P&gt;</description>
    <pubDate>Thu, 21 Nov 2019 08:03:16 GMT</pubDate>
    <dc:creator>Xinhui</dc:creator>
    <dc:date>2019-11-21T08:03:16Z</dc:date>
    <item>
      <title>Create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606031#M175932</link>
      <description>&lt;P&gt;Hi there&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a variable "dd", data range is from -15 to 90,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a new variable T, which if DD from 0- -5 t would be -1&lt;/P&gt;&lt;P&gt;-5--10 t would be -2&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;0-5&amp;nbsp; t would be 1&amp;nbsp;&lt;/P&gt;&lt;P&gt;6-10 t would be 2&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on.&lt;/P&gt;&lt;P&gt;But I don't know how to code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me to figure out the solusion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 07:29:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606031#M175932</guid>
      <dc:creator>Xinhui</dc:creator>
      <dc:date>2019-11-21T07:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606033#M175934</link>
      <description>&lt;P&gt;You can either create a format is you have many ranges to be mappes. Otherwise, simply use if-then-else logic and use this as a template&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   do i=1 to 10;
      dd=ceil(rand('uniform')*20);
      output;
   end;
run;

data want;
    set have;
    if      0 &amp;lt;= dd &amp;lt;  5  then t=-1;
    else if 5 &amp;lt;= dd &amp;lt;= 10 then t=0;
    else                       t=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Nov 2019 07:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606033#M175934</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-21T07:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606034#M175935</link>
      <description>&lt;P&gt;DATA T;&lt;BR /&gt;SET FULL;&lt;BR /&gt;if 15 &amp;lt;= dd &amp;lt; 10 then t=-3;&lt;BR /&gt;else if 10 &amp;lt;= dd &amp;lt; 5 then t=-2;&lt;BR /&gt;else if 5 &amp;lt;= dd &amp;lt; 0 then t=-1;&lt;BR /&gt;else if 0 &amp;lt;= dd &amp;lt; -5 then t= 1;&lt;BR /&gt;else if -5 &amp;lt;= dd &amp;lt; -10 then t= 2;&lt;BR /&gt;else if -10 &amp;lt;= dd &amp;lt; -15 then t= 3;&lt;BR /&gt;else if -15 &amp;lt;= dd &amp;lt; -20 then t= 4;&lt;BR /&gt;else if -20 &amp;lt;= dd &amp;lt; -25 then t= 5;&lt;BR /&gt;else if -25 &amp;lt;= dd &amp;lt; -30 then t= 6;&lt;BR /&gt;else if -30 &amp;lt;= dd &amp;lt; -35 then t= 7;&lt;BR /&gt;else if -35 &amp;lt;= dd &amp;lt; -40 then t= 8;&lt;BR /&gt;else if -40 &amp;lt;= dd &amp;lt; -45 then t= 9;&lt;BR /&gt;else if -45 &amp;lt;= dd &amp;lt; -50 then t= 10;&lt;BR /&gt;else if -50 &amp;lt;= dd &amp;lt; -55 then t= 11;&lt;BR /&gt;else if -55 &amp;lt;= dd &amp;lt; -60 then t= 12;&lt;BR /&gt;else if -60 &amp;lt;= dd &amp;lt; -65 then t= 13;&lt;BR /&gt;else if -65 &amp;lt;= dd &amp;lt; -70 then t= 14;&lt;BR /&gt;else if -70 &amp;lt;= dd &amp;lt; -75 then t= 15;&lt;BR /&gt;else if -75 &amp;lt;= dd &amp;lt; -80 then t= 16;&lt;BR /&gt;else if -80 &amp;lt;= dd &amp;lt; -85 then t= 17;&lt;BR /&gt;else if -85 &amp;lt;= dd &amp;lt; -90 then t= 18;&lt;BR /&gt;else t=.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I tried this code, not work.&lt;/P&gt;&lt;P&gt;DD is from -90 to 15&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 08:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606034#M175935</guid>
      <dc:creator>Xinhui</dc:creator>
      <dc:date>2019-11-21T08:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606035#M175936</link>
      <description>&lt;P&gt;What do you mean when you say 'does not work'? Does it yield and error? Please do not make us guess &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, here is a hint. Look at this code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 15 &amp;lt;= dd &amp;lt; 10 then t=-3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This can never be true. A number can not be less than 10 &lt;EM&gt;and&amp;nbsp;&lt;/EM&gt;larger than or equal to 15. The error is in your ranges.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 08:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606035#M175936</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-21T08:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606054#M175940</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example using a format created with cntlin option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ctrl;
    fmtname="xinhui";
    type="n";
    do start=-90 to 10 by 5;
        end=start+5;
        if end&amp;gt;0 then label=put(-end/5, best.);
        else label=put(-start/5, best.);
        output;
    end;
    label=".";
    hlo="O";
    output;
run;

proc format cntlin=ctrl;
run;

data have;
    input x;
    cards;
-25
-30
12
8
-49
-67
35
;
run;

proc print data=have;
    format x xinhui.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Nov 2019 08:53:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606054#M175940</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-11-21T08:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606071#M175948</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/124145"&gt;@Xinhui&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you can try this code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set full;
	
	do i=-3 to -1;
		if (5*i) &amp;lt;= dd &amp;lt;  (5*i)+5 then t=i;
	end;
	
	do i=1 to 18;
		if (5*i)-5 &amp;lt; dd &amp;lt;=  (5*i) then t=i;
	end;
	
	if dd=0 then t=1;
	
	drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, as said by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;, you need to be very clear on what are the bounds for each category of t, and whether lower / upper bounds are included or not (&amp;lt; or &amp;lt;=).&lt;/P&gt;
&lt;P&gt;e.g. I understand that you want the lower bound to be included when dd is negative&amp;nbsp;[-15;-10] [-10;-5] etc.&lt;/P&gt;
&lt;P&gt;but it should not be the case when dd is positive: &lt;FONT color="#FF0000"&gt;]&lt;/FONT&gt;5;10] &lt;FONT color="#FF0000"&gt;]&lt;/FONT&gt;10;15] etc. &amp;nbsp;exceptionalities for the first category :&amp;nbsp;[0;1]&lt;/P&gt;
&lt;P&gt;Is that right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 10:23:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606071#M175948</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-11-21T10:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606132#M175976</link>
      <description>&lt;P&gt;Depending on how you answer the boundary questions ... what should T be when dd=0?&amp;nbsp; when dd=-5? ... here is one approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if dd=0 then t=0;
else if dd &amp;gt; 0 then t = ceil(dd/5);
else t = floor(dd/5);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Nov 2019 13:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606132#M175976</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-11-21T13:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606245#M176029</link>
      <description>&lt;P&gt;You code such as&lt;/P&gt;
&lt;PRE&gt;else if -85 &amp;lt;= dd &amp;lt; -90 then t= 18;&lt;/PRE&gt;
&lt;P&gt;Is never true. -95 is SMALLER than -85, not larger. So you cannot have a value that is both larger than -85 and less than -90.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 18:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/606245#M176029</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-21T18:16:35Z</dc:date>
    </item>
  </channel>
</rss>

