<?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: Troubleshooting - Code Not Applying To Subgroup in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/641787#M191351</link>
    <description>Yes!  That was an original problem I thought I had fixed. But now I see it did not pull through. May be the result of working on too many datasets simultaneously. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;  I will recheck and then respond to this thread to hopefully close it out.  &lt;BR /&gt;Thank you!&lt;BR /&gt;</description>
    <pubDate>Wed, 22 Apr 2020 00:13:36 GMT</pubDate>
    <dc:creator>anissak1</dc:creator>
    <dc:date>2020-04-22T00:13:36Z</dc:date>
    <item>
      <title>Troubleshooting - Code Not Applying To Subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/641766#M191337</link>
      <description>&lt;P&gt;Hello - I have written the code below for a dataset.&amp;nbsp; I'm creating new variables based on existing variables.&lt;/P&gt;
&lt;P&gt;When I run this code, there is &lt;U&gt;one subgroup&lt;/U&gt; for whom the walkcensordate variable (a new variable) does not get created properly.&amp;nbsp; Rather, it is assigned another variable value - censor date - which is not in the code below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run the code on the entire dataset, it works perfectly fine except for in the problematic subgroup.&amp;nbsp; And if I isolate a single patient from this subgroup, the code also runs fine.&lt;/P&gt;
&lt;P&gt;Any ideas on how to troubleshoot?&amp;nbsp; The subgroups to which I refer were created at the same time - not from a merge. And the problematic variable did not exist previously. Is there another way I could approach writing my code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel there is an error on the back end somehow or maybe that I am just going mad. &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;Thank you!&lt;/P&gt;
&lt;P&gt;Anissa&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data check3;&lt;BR /&gt;set check2;&lt;BR /&gt;if t25confirmedprogress=1 then walkcensor=1;&lt;BR /&gt;else walkcensor=0;&lt;BR /&gt;if walkcensor=1 then walkcensordate=first_day;&lt;BR /&gt;if term=0 then walkcensordate=termdate;&lt;BR /&gt;if walkcensordate='.' then walkcensordate=edsslof;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2020 22:30:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/641766#M191337</guid>
      <dc:creator>anissak1</dc:creator>
      <dc:date>2020-04-21T22:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting - Code Not Applying To Subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/641767#M191338</link>
      <description>&lt;P&gt;Is your Walkcensordate character or numeric.&lt;/P&gt;
&lt;P&gt;This code seldom makes sense:&lt;/P&gt;
&lt;PRE&gt;if walkcensordate='.' then walkcensordate=edsslof;&lt;/PRE&gt;
&lt;P&gt;if the variable is character then a missing value is not '.'&lt;/P&gt;
&lt;P&gt;If the variable is numeric you likely get a "conversion to numeric" note in the log and may not be comparing the desired value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to check for missing values then you may want to use the function MISSING, which will work for both numeric and character values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if missing(walkcensordate)  then walkcensordate=edsslof;&lt;/PRE&gt;
&lt;P&gt;Other than that, you should provide the values of all the variables you are showing in the code, in the form of a data step, that are not getting assigned correctly for whatever subgroup.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is not impossible that a logic problem when you create check2 added the variable/value you don't want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2020 22:41:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/641767#M191338</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-21T22:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting - Code Not Applying To Subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/641773#M191342</link>
      <description>&lt;P&gt;Thank you for the note! I'll double check on character format and the other steps your noted in your message.&amp;nbsp; The original dataset came to me from R in csv format and I definitely had some character/numeric formatting issues earlier on (that I thought I had resolved).&amp;nbsp; Should get to this tonight or tomorrow morning.&amp;nbsp; My brain is fried from a few hours of troubleshooting code in general and I'm currently worried that I'll introduce more errors. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; My fingers are crossed!...&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2020 22:58:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/641773#M191342</guid>
      <dc:creator>anissak1</dc:creator>
      <dc:date>2020-04-21T22:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting - Code Not Applying To Subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/641776#M191345</link>
      <description>&lt;P&gt;Does the original R dataframe have missing values? R has a nasty habit of writing character strings into CSV file for the missing values.&amp;nbsp;You should probably pre-process the CSV files to remove those NA strings so they don't get you confused about the variable types.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2020 23:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/641776#M191345</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-21T23:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting - Code Not Applying To Subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/641787#M191351</link>
      <description>Yes!  That was an original problem I thought I had fixed. But now I see it did not pull through. May be the result of working on too many datasets simultaneously. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;  I will recheck and then respond to this thread to hopefully close it out.  &lt;BR /&gt;Thank you!&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Apr 2020 00:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/641787#M191351</guid>
      <dc:creator>anissak1</dc:creator>
      <dc:date>2020-04-22T00:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting - Code Not Applying To Subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/641846#M191386</link>
      <description>&lt;P&gt;Quick check on your SAS data set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc Contents data=check2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;to tell you the variable types and such.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc freq data=check2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;tables t25confirmedprogress;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;with a tables statement will tell you values of the variables of interest and how many missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure if you realize that your ELSE will execute when t25confirmedprogress is missing. Since that is the first comparison that might be part of your issue.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Best practice is to provide an example of data we can use in the form of a data step. It should include some cases that have the "problem" and some that don't.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basic rule: quotes only go with Character variable values. If you look at data (print, view table or similar) and see a dot that is very likely the missing value indicator for numeric values. Which would come from a numeric variable with a value like NA in a CSV file.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 08:32:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/641846#M191386</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-22T08:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting - Code Not Applying To Subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/642024#M191476</link>
      <description>&lt;P&gt;I'm not sure what to mark as the correct solution as I was unable to "fix" the code.&amp;nbsp; To resolve it, I used the original dataset that didn't pull through the one line of code correctly to the subpopulation and wrote a new line of code on a new dataset (below).&amp;nbsp; This brute force approach did pull through all observations, including the subgroup that didn't "take" before.&amp;nbsp; I confirmed that all variables were numerical.&amp;nbsp; And so I am still scratching my head why a certain set of observations would not take the "first_day" value.&amp;nbsp; But moving on...:)&amp;nbsp; Thanks to all for your guidance.&amp;nbsp; Super helpful, as always.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data kaplan8;&lt;BR /&gt;set kaplan7;&lt;BR /&gt;if t25confirmedprogress=1 then walkcensor=1;&lt;BR /&gt;else walkcensor=0;&lt;BR /&gt;if walkcensor=1 then walkcensordate=first_day;&lt;BR /&gt;if term=0 then walkcensordate=termdate;&lt;BR /&gt;if missing (walkcensordate) then walkcensordate=edsslof;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data kaplan100;&lt;BR /&gt;set kaplan8;&lt;BR /&gt;if t25confirmedprogress=1 then walkcensordate=first_day;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 17:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/642024#M191476</guid>
      <dc:creator>anissak1</dc:creator>
      <dc:date>2020-04-22T17:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting - Code Not Applying To Subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/642029#M191480</link>
      <description>&lt;P&gt;You might test instead of&lt;/P&gt;
&lt;PRE&gt;if t25confirmedprogress=1 then walkcensor=1;
else walkcensor=0;
if walkcensor=1 then walkcensordate=first_day;&lt;/PRE&gt;
&lt;P&gt;try&lt;/P&gt;
&lt;PRE&gt;if t25confirmedprogress=1 then do;
   walkcensor=1;
   walkcensordate=first_day;
end;  
else walkcensor=0;
&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Apr 2020 17:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/642029#M191480</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-22T17:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting - Code Not Applying To Subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/642032#M191483</link>
      <description>&lt;P&gt;Since you have multiple independent statement that are setting the same variable WALCENSORDATE then order that you run them makes a difference.&amp;nbsp; If two conditions are both true then the value assigned by the last one "wins".&amp;nbsp; Adding a little spacing as below makes it is easier to see which blocks of statements are independent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to skip creating the extra data step then just add the extra IF to the first data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data kaplan100;
set kaplan7;

if t25confirmedprogress=1 then walkcensor=1;
else walkcensor=0;

if walkcensor=1 then walkcensordate=first_day;

if term=0 then walkcensordate=termdate;

if missing (walkcensordate) then walkcensordate=edsslof;

if t25confirmedprogress=1 then walkcensordate=first_day;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to combine those last 4 into once IF/THEN/ELSE IF... sequence then make sure to reverse the order.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data kaplan100;
set kaplan7;

if t25confirmedprogress=1 then walkcensor=1;
else walkcensor=0;

if t25confirmedprogress=1 then walkcensordate=first_day;
else if missing (walkcensordate) then walkcensordate=edsslof;
else if term=0 then walkcensordate=termdate;
else if walkcensor=1 then walkcensordate=first_day;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Apr 2020 17:44:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/642032#M191483</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-22T17:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting - Code Not Applying To Subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/642037#M191487</link>
      <description>&lt;P&gt;BOTH of these solutions worked.&amp;nbsp; I wish I could mark them as solutions!!!&lt;/P&gt;
&lt;P&gt;I didn't "see" the flaws in the logic of my original code.&amp;nbsp; So helpful to see these pointed out - and in two different ways.&amp;nbsp; I'm still not sure why exactly my original code would work for 2100 observations but not 300 of them.&amp;nbsp; But perhaps I should leave that for a different day.&amp;nbsp; MUCH appreciation Tom!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 18:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Troubleshooting-Code-Not-Applying-To-Subgroup/m-p/642037#M191487</guid>
      <dc:creator>anissak1</dc:creator>
      <dc:date>2020-04-22T18:00:53Z</dc:date>
    </item>
  </channel>
</rss>

