<?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 Create new variable based on threshold in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-threshold/m-p/368995#M275529</link>
    <description>&lt;P&gt;I have this longitudinal data&lt;BR /&gt;id &amp;nbsp;PD&lt;BR /&gt;01 &amp;nbsp;0.5&lt;BR /&gt;01 &amp;nbsp;1.0&lt;BR /&gt;01 &amp;nbsp;1.5&lt;BR /&gt;01 &amp;nbsp;0.9&lt;BR /&gt;01 &amp;nbsp;1.6&lt;BR /&gt;01 &amp;nbsp;1.1&lt;BR /&gt;02 &amp;nbsp;1.5&lt;BR /&gt;02 &amp;nbsp;1.0&lt;BR /&gt;02 &amp;nbsp;1.5&lt;BR /&gt;02 &amp;nbsp;1.5&lt;BR /&gt;02 &amp;nbsp;1.7&lt;BR /&gt;03 &amp;nbsp;1.2&lt;BR /&gt;03 &amp;nbsp;1.5&lt;BR /&gt;03 &amp;nbsp;1.0&lt;BR /&gt;03 &amp;nbsp;1.5&lt;BR /&gt;03 &amp;nbsp;0.5&lt;BR /&gt;03 &amp;nbsp;1.7&lt;BR /&gt;03 &amp;nbsp;1.2&lt;BR /&gt;04 &amp;nbsp;0.2&lt;BR /&gt;04 &amp;nbsp;0.5&lt;BR /&gt;04 &amp;nbsp;0.6&lt;BR /&gt;04 &amp;nbsp;0.5&lt;BR /&gt;04 &amp;nbsp;0.5&lt;BR /&gt;04 &amp;nbsp;0.7&lt;BR /&gt;04 &amp;nbsp;0.2&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;For each id, the PD value fluctuate between 0 and 1.7.&lt;/P&gt;
&lt;P&gt;I have this three categories: i) PD&amp;gt;1.15 , ii) 0.9&amp;lt;PD&amp;lt;=1.15 iii) PD&amp;lt;=0.9&lt;BR /&gt;For some id, PD will fluctuate within the three groups. I want to create a third variable GroupPD and call such group "A", that is the id will &lt;BR /&gt;have correspondent GroupPD value "A". b) if PD fluctuate between PD&amp;gt;1.15 and 0.9&amp;lt;PD&amp;lt;=1.15 the GroupPD value will be "B". c) if PD fluctuate between PD&amp;gt;1.15 and PD&amp;lt;=0.9&lt;BR /&gt;the GroupPD value will be "C" d) if PD fluctuate between 0.9&amp;lt;PD&amp;lt;=1.15 and PD&amp;lt;=0.9 GroupPD value will be "D" e) If PD stayed within PD&amp;gt;1.15, then GroupPD will be "E"&lt;BR /&gt;f) If PD stayed within &amp;lt;0.9PD&amp;lt;=1.15, then GroupPD will be "F" g) If PD stayed within PD&amp;lt;=0.9, then GroupPD will be "G"&lt;/P&gt;
&lt;P&gt;Please can I have code to help me do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Expected output&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;id &amp;nbsp;PD &amp;nbsp;GroupPD&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;01 &amp;nbsp;0.5 A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;01 &amp;nbsp;1.0 &amp;nbsp;A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;01 &amp;nbsp;1.5 &amp;nbsp;A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;01 &amp;nbsp;0.9 &amp;nbsp;A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;01 &amp;nbsp;1.6 &amp;nbsp;A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;01 &amp;nbsp;1.1 &amp;nbsp;A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;02 &amp;nbsp;1.5 B&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;02 &amp;nbsp;1.0 B&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;02 &amp;nbsp;1.5 B&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;02 &amp;nbsp;1.5 B&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;02 &amp;nbsp;1.7 B&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;03 &amp;nbsp;1.2 C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;03 &amp;nbsp;1.5 C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;03 &amp;nbsp;1.0 C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;03 &amp;nbsp;1.5 C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;03 &amp;nbsp;0.5 C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;03 &amp;nbsp;1.7 C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;03 &amp;nbsp;1.2 C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;04 &amp;nbsp;0.2 G&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;04 &amp;nbsp;0.5 G&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;04 &amp;nbsp;0.6 G&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;04 &amp;nbsp;0.5 G&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;04 &amp;nbsp;0.5 G&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;04 &amp;nbsp;0.7 G&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;04 &amp;nbsp;0.2 G&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 21 Jun 2017 03:50:44 GMT</pubDate>
    <dc:creator>desireatem</dc:creator>
    <dc:date>2017-06-21T03:50:44Z</dc:date>
    <item>
      <title>Create new variable based on threshold</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-threshold/m-p/368995#M275529</link>
      <description>&lt;P&gt;I have this longitudinal data&lt;BR /&gt;id &amp;nbsp;PD&lt;BR /&gt;01 &amp;nbsp;0.5&lt;BR /&gt;01 &amp;nbsp;1.0&lt;BR /&gt;01 &amp;nbsp;1.5&lt;BR /&gt;01 &amp;nbsp;0.9&lt;BR /&gt;01 &amp;nbsp;1.6&lt;BR /&gt;01 &amp;nbsp;1.1&lt;BR /&gt;02 &amp;nbsp;1.5&lt;BR /&gt;02 &amp;nbsp;1.0&lt;BR /&gt;02 &amp;nbsp;1.5&lt;BR /&gt;02 &amp;nbsp;1.5&lt;BR /&gt;02 &amp;nbsp;1.7&lt;BR /&gt;03 &amp;nbsp;1.2&lt;BR /&gt;03 &amp;nbsp;1.5&lt;BR /&gt;03 &amp;nbsp;1.0&lt;BR /&gt;03 &amp;nbsp;1.5&lt;BR /&gt;03 &amp;nbsp;0.5&lt;BR /&gt;03 &amp;nbsp;1.7&lt;BR /&gt;03 &amp;nbsp;1.2&lt;BR /&gt;04 &amp;nbsp;0.2&lt;BR /&gt;04 &amp;nbsp;0.5&lt;BR /&gt;04 &amp;nbsp;0.6&lt;BR /&gt;04 &amp;nbsp;0.5&lt;BR /&gt;04 &amp;nbsp;0.5&lt;BR /&gt;04 &amp;nbsp;0.7&lt;BR /&gt;04 &amp;nbsp;0.2&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;For each id, the PD value fluctuate between 0 and 1.7.&lt;/P&gt;
&lt;P&gt;I have this three categories: i) PD&amp;gt;1.15 , ii) 0.9&amp;lt;PD&amp;lt;=1.15 iii) PD&amp;lt;=0.9&lt;BR /&gt;For some id, PD will fluctuate within the three groups. I want to create a third variable GroupPD and call such group "A", that is the id will &lt;BR /&gt;have correspondent GroupPD value "A". b) if PD fluctuate between PD&amp;gt;1.15 and 0.9&amp;lt;PD&amp;lt;=1.15 the GroupPD value will be "B". c) if PD fluctuate between PD&amp;gt;1.15 and PD&amp;lt;=0.9&lt;BR /&gt;the GroupPD value will be "C" d) if PD fluctuate between 0.9&amp;lt;PD&amp;lt;=1.15 and PD&amp;lt;=0.9 GroupPD value will be "D" e) If PD stayed within PD&amp;gt;1.15, then GroupPD will be "E"&lt;BR /&gt;f) If PD stayed within &amp;lt;0.9PD&amp;lt;=1.15, then GroupPD will be "F" g) If PD stayed within PD&amp;lt;=0.9, then GroupPD will be "G"&lt;/P&gt;
&lt;P&gt;Please can I have code to help me do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Expected output&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;id &amp;nbsp;PD &amp;nbsp;GroupPD&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;01 &amp;nbsp;0.5 A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;01 &amp;nbsp;1.0 &amp;nbsp;A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;01 &amp;nbsp;1.5 &amp;nbsp;A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;01 &amp;nbsp;0.9 &amp;nbsp;A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;01 &amp;nbsp;1.6 &amp;nbsp;A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;01 &amp;nbsp;1.1 &amp;nbsp;A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;02 &amp;nbsp;1.5 B&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;02 &amp;nbsp;1.0 B&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;02 &amp;nbsp;1.5 B&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;02 &amp;nbsp;1.5 B&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;02 &amp;nbsp;1.7 B&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;03 &amp;nbsp;1.2 C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;03 &amp;nbsp;1.5 C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;03 &amp;nbsp;1.0 C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;03 &amp;nbsp;1.5 C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;03 &amp;nbsp;0.5 C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;03 &amp;nbsp;1.7 C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;03 &amp;nbsp;1.2 C&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;04 &amp;nbsp;0.2 G&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;04 &amp;nbsp;0.5 G&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;04 &amp;nbsp;0.6 G&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;04 &amp;nbsp;0.5 G&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;04 &amp;nbsp;0.5 G&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;04 &amp;nbsp;0.7 G&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;04 &amp;nbsp;0.2 G&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 03:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-threshold/m-p/368995#M275529</guid>
      <dc:creator>desireatem</dc:creator>
      <dc:date>2017-06-21T03:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on threshold</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-threshold/m-p/369003#M275530</link>
      <description>&lt;P&gt;Please show us the expected output for better response&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 03:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-threshold/m-p/369003#M275530</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2017-06-21T03:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on threshold</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-threshold/m-p/369004#M275531</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
  input id $ 1-2 pd;
  datalines;
01  0.5
01  1.0
01  1.5
01  0.9
01  1.6
01  1.1
02  1.5
02  1.0
02  1.5
02  0.5
02  1.7
03  1.2
03  1.5
03  1.0
03  1.5
03  0.5
03  1.7
03  1.2
04  0.2
04  0.5
04  0.6
04  0.5
04  0.5
04  0.7
04  0.2
;
run;

proc print data=have;
run;

* sort data set if not already sorted by id;

data want(drop=low medium high pd);
  retain low medium high;
  set have;
  by id;
  if first.id then
    do;
      low=0;
      medium=0;
      high=0;
    end;
  if pd le 0.9 then low+1;
  else if 0.9 lt pd le 1.15 then medium+1;
  else if pd gt 1.15 then high+1;
  if last.id then 
    do;
      groupPD='A';
      if (low=0 and medium gt 0 and high gt 0) then groupPD='B';
      else if (low gt 0 and medium=0 and high gt 0) then groupPD='C';
      else if (low gt 0 and medium gt 0 and high=0) then groupPD='D';
      else if (low=0 and medium=0 and high gt 0) then groupPD='E';
      else if (low=0 and medium gt 0 and high=0) then groupPD='F';
      else if (low gt 0 and medium=0 and  high=0) then groupPD='G';
      output;
    end;
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Jun 2017 03:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-threshold/m-p/369004#M275531</guid>
      <dc:creator>SuzanneDorinski</dc:creator>
      <dc:date>2017-06-21T03:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on threshold</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-threshold/m-p/369005#M275532</link>
      <description>&lt;P&gt;Thank you very much!!!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 03:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-threshold/m-p/369005#M275532</guid>
      <dc:creator>desireatem</dc:creator>
      <dc:date>2017-06-21T03:53:29Z</dc:date>
    </item>
  </channel>
</rss>

