<?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: Assigning a value if a condition is met in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Assigning-a-value-if-a-condition-is-met/m-p/623910#M20028</link>
    <description>&lt;P&gt;It sounds like you want something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   input ID   Score   Risk0     Risk1       Risk2       Risk3       Risk4   ;
datalines;
12      0         0.1          0.5           0.6          0.2          0.12
15      3         0.4          0.6           0.7          0.1          0.39
10      1         0.2          0.3           0.4          0.5          0.67
;
data want;
   set have;
   array r(0:4) risk0-risk4;
   Risk=r[score];
run;&lt;/PRE&gt;
&lt;P&gt;Often when you want to treat a group of variables in some manner an array is appropriate. The definition of this array says that the index values start at 0, which is one of your score values. So r[0] references Risk0, r[1] is Risk1 etc. Then use the Score as the index value to access the desired variable.&lt;/P&gt;</description>
    <pubDate>Tue, 11 Feb 2020 17:18:26 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-02-11T17:18:26Z</dc:date>
    <item>
      <title>Assigning a value if a condition is met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assigning-a-value-if-a-condition-is-met/m-p/623907#M20025</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table as follows where score has a value from 0 to 4, and corresponding to each value of the score I have a column for risk.&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;Score&amp;nbsp; &amp;nbsp;Risk0&amp;nbsp; &amp;nbsp; &amp;nbsp;Risk1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Risk2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Risk3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Risk4&lt;/P&gt;&lt;P&gt;12&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.12&lt;/P&gt;&lt;P&gt;15&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.39&lt;/P&gt;&lt;P&gt;10&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.67&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to have a new variable like Risk where its value depends on Score. For example for observation with ID=12, since Score=0, I want to have Risk=Risk0=0.1, similarly for ID=10, Risk should be Risk=Risk1=0.3.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 16:59:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assigning-a-value-if-a-condition-is-met/m-p/623907#M20025</guid>
      <dc:creator>Bright</dc:creator>
      <dc:date>2020-02-11T16:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning a value if a condition is met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assigning-a-value-if-a-condition-is-met/m-p/623908#M20026</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Score Risk0 Risk1 Risk2 Risk3 Risk4;
datalines;
12 0 0.1 0.5 0.6 0.2 0.12
15 3 0.4 0.6 0.7 0.1 0.39
10 1 0.2 0.3 0.4 0.5 0.67
;

data want;
   set have;
   array _ {0:4} Risk0-Risk4;
   Risk = _ [Score];
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID Score Risk0 Risk1 Risk2 Risk3 Risk4  Risk 
12 0     0.1   0.5   0.6   0.2   0.12   0.1 
15 3     0.4   0.6   0.7   0.1   0.39   0.1 
10 1     0.2   0.3   0.4   0.5   0.67   0.3 &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 17:16:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assigning-a-value-if-a-condition-is-met/m-p/623908#M20026</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-02-11T17:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning a value if a condition is met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assigning-a-value-if-a-condition-is-met/m-p/623909#M20027</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/307632"&gt;@Bright&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an attempt to do this, using an array:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	array _Risk(0:4) Risk0-Risk4;
	Risk = _Risk(score);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Feb 2020 17:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assigning-a-value-if-a-condition-is-met/m-p/623909#M20027</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-11T17:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning a value if a condition is met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assigning-a-value-if-a-condition-is-met/m-p/623910#M20028</link>
      <description>&lt;P&gt;It sounds like you want something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   input ID   Score   Risk0     Risk1       Risk2       Risk3       Risk4   ;
datalines;
12      0         0.1          0.5           0.6          0.2          0.12
15      3         0.4          0.6           0.7          0.1          0.39
10      1         0.2          0.3           0.4          0.5          0.67
;
data want;
   set have;
   array r(0:4) risk0-risk4;
   Risk=r[score];
run;&lt;/PRE&gt;
&lt;P&gt;Often when you want to treat a group of variables in some manner an array is appropriate. The definition of this array says that the index values start at 0, which is one of your score values. So r[0] references Risk0, r[1] is Risk1 etc. Then use the Score as the index value to access the desired variable.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 17:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assigning-a-value-if-a-condition-is-met/m-p/623910#M20028</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-02-11T17:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning a value if a condition is met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assigning-a-value-if-a-condition-is-met/m-p/624082#M20059</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Score Risk0 Risk1 Risk2 Risk3 Risk4;
datalines;
12 0 0.1 0.5 0.6 0.2 0.12
15 3 0.4 0.6 0.7 0.1 0.39
10 1 0.2 0.3 0.4 0.5 0.67
;

data want;
 set have;
 Risk=vvaluex(cats('risk',Score));
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Feb 2020 05:36:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assigning-a-value-if-a-condition-is-met/m-p/624082#M20059</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-02-12T05:36:53Z</dc:date>
    </item>
  </channel>
</rss>

