<?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: Simple data management question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Simple-data-management-question/m-p/411238#M100529</link>
    <description>&lt;P&gt;Just update it to reflect your logic:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  select (dlpp1);
    when (1) hb_dlpp1=0;
    when (2) hb_dlpp1=1;
    when (-99) do;
      if pdet=1 then hbdlpp1=1;&lt;BR /&gt;      if pdet=2 then hpdlpp1=0;&lt;BR /&gt;      if pdet=. then hdlpp1=.;&lt;BR /&gt;      if pdet=-99 then hldpp1=-99;
    end;
    otherwise hb_dlpp1=.;
  end;
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 07 Nov 2017 16:21:32 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-11-07T16:21:32Z</dc:date>
    <item>
      <title>Simple data management question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-data-management-question/m-p/411152#M100498</link>
      <description>&lt;P&gt;I'm going nuts trying to figure out where my coding error is. Can anyone&amp;nbsp;tell me what I'm doing wrong?&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I'm trying to define a new variable called "HB_DLPP1". HB_DLPP1 can be =0 (no) and 1(yes) or -99 (unmeasured) or . (missing). This variable incorporates another variable called "DLPP1". DLPP1 can be = 1, =2, =-99, or =. When DLPP1 is = -99, I want SAS to use the information from a different&amp;nbsp;variable called "Pdet1" to define HB_DLPP1. Pdet1 can be =1, =2, =-99, or = .&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I wrote the following code:&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If DLPP1 = 1 then HB_DLPP1 = 0;&lt;/DIV&gt;&lt;DIV&gt;Else if DLPP1 = 2 then HB_DLPP1 = 1;&lt;/DIV&gt;&lt;DIV&gt;Else if DLPP1 = -99 AND Pdet1 = 1 then HB_DLPP1 = 0;&lt;/DIV&gt;&lt;DIV&gt;Else if DLPP1 = -99 AND Pdet1 = 2 then HB_DLPP1 = 1;&lt;/DIV&gt;&lt;DIV&gt;Else HB_DLPP1 = .;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;It works perfectly except for&amp;nbsp;the&amp;nbsp;highlighted line, where I want HB_DLPP1 = 0 bc DLPP1 = -99 and Pdet = 1.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;What do I need to change to make this assign the correct values??&lt;/DIV&gt;&amp;nbsp;&lt;IMG src="blob:https://communities.sas.com/504912fc-c05e-42de-9de4-9368d6b6689b" border="0" width="528" height="331" /&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 07 Nov 2017 12:44:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-data-management-question/m-p/411152#M100498</guid>
      <dc:creator>bkv1</dc:creator>
      <dc:date>2017-11-07T12:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: Simple data management question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-data-management-question/m-p/411163#M100506</link>
      <description>&lt;P&gt;Its always a good idea to post test data as a datastep in the post to show what you have, and example of what you want out.&amp;nbsp; Its very hard to tell from what you have posted, anything which is happening.&amp;nbsp; I would maybe write it like this:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  select (dlpp1);
    when (1) hb_dlpp1=0;
    when (2) hb_dlpp1=1;
    when (-99) hb_dlpp1=ifn(pdet1=1,0,1);
    otherwise hb_dlpp1=.;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Note how I don't use mixed case.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 13:02:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-data-management-question/m-p/411163#M100506</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-07T13:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Simple data management question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-data-management-question/m-p/411207#M100524</link>
      <description>&lt;P&gt;The rest of us have now officially joined you (going nuts, that is).&amp;nbsp; There's nothing wrong with the code you posted.&amp;nbsp; Perhaps there's something going on in the larger context of the DATA step since you posted just a portion of the DATA step.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 14:55:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-data-management-question/m-p/411207#M100524</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-11-07T14:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Simple data management question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-data-management-question/m-p/411225#M100527</link>
      <description>&lt;P&gt;MANY THANKS FOR YOUR HELP! This fixed the specific problem, but then it handled -99 and . differently. When both are -99 hb_dlpp1&amp;nbsp;should = -99, and when one is -99 and the other ., it should = . 9 (see below):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="blob:https://communities.sas.com/13426dcc-28cb-4346-8b0c-17115aed08fc" border="0" width="494" height="173" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I forced it to give me the right results by adding the additional &amp;nbsp;2 lines of code, but is there a more elegant way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if dlpp1 = -99 AND pdet1 = . then hb_dlpp1 = .;&lt;/P&gt;&lt;P&gt;if dlpp1 = -99 and pdet1 = -99 then hb_dlpp1 = -99;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 16:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-data-management-question/m-p/411225#M100527</guid>
      <dc:creator>bkv1</dc:creator>
      <dc:date>2017-11-07T16:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Simple data management question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-data-management-question/m-p/411238#M100529</link>
      <description>&lt;P&gt;Just update it to reflect your logic:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  select (dlpp1);
    when (1) hb_dlpp1=0;
    when (2) hb_dlpp1=1;
    when (-99) do;
      if pdet=1 then hbdlpp1=1;&lt;BR /&gt;      if pdet=2 then hpdlpp1=0;&lt;BR /&gt;      if pdet=. then hdlpp1=.;&lt;BR /&gt;      if pdet=-99 then hldpp1=-99;
    end;
    otherwise hb_dlpp1=.;
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Nov 2017 16:21:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-data-management-question/m-p/411238#M100529</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-07T16:21:32Z</dc:date>
    </item>
  </channel>
</rss>

