<?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: If/then with missing data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572481#M161549</link>
    <description>&lt;P&gt;I was showing the results of a frequency to illustrate my point that their are missing data that I should be able to write code to capture. That is why their are variable in my code that you do not see. Thank you for the input&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jul 2019 19:01:54 GMT</pubDate>
    <dc:creator>GS2</dc:creator>
    <dc:date>2019-07-10T19:01:54Z</dc:date>
    <item>
      <title>If/then with missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572463#M161545</link>
      <description>&lt;P&gt;Using SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am writing an if/then statement to move data from one variable to another if the data is blank (see below for code). However when I run the code the data is not populating into the new variable. Based on the frequency below I know that their are 149 blank entries. The format for variable 'first_dx' is&amp;nbsp;$CHAR4 so the ' ' method should work to capture the blank entries. Any thoughts would be helpful. Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.demog_crstar_pt_level_final;&lt;BR /&gt;set work.demog_crstar_pt_level;&lt;BR /&gt;if first_dx = ' ' then first_dx = topography_code;&lt;BR /&gt;set work.demog_crstar_pt_level;&lt;BR /&gt;if first_dx_desc = ' ' then first_dx_desc = topography_code_desc;&lt;BR /&gt;set work.demog_crstar_pt_level;&lt;BR /&gt;if first_dx_date = . then first_dx_date = date_of_diagnosis;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;first_dx Frequency Percent Frequency Percent&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 149&amp;nbsp; &amp;nbsp;73.76 149&amp;nbsp; &amp;nbsp;73.76&lt;BR /&gt;C619&amp;nbsp; &amp;nbsp;46&amp;nbsp; &amp;nbsp; &amp;nbsp;22.77 195&amp;nbsp; &amp;nbsp;96.53&lt;BR /&gt;C669&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.50&amp;nbsp; &amp;nbsp;196&amp;nbsp; &amp;nbsp;97.03&lt;BR /&gt;C672&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.99&amp;nbsp; &amp;nbsp;198&amp;nbsp; &amp;nbsp;98.02&lt;BR /&gt;C674&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0.50&amp;nbsp; &amp;nbsp; 199&amp;nbsp; &amp;nbsp;98.51&lt;BR /&gt;C678&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 0.99&amp;nbsp; &amp;nbsp; 201&amp;nbsp; &amp;nbsp;99.50&lt;BR /&gt;C679&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0.50&amp;nbsp; &amp;nbsp; 202&amp;nbsp; &amp;nbsp;100.00&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 18:14:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572463#M161545</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2019-07-10T18:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: If/then with missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572471#M161546</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;first_dx Frequency Percent Frequency Percent&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 149&amp;nbsp; &amp;nbsp;73.76 149&amp;nbsp; &amp;nbsp;73.76&lt;BR /&gt;C619&amp;nbsp; &amp;nbsp;46&amp;nbsp; &amp;nbsp; &amp;nbsp;22.77 195&amp;nbsp; &amp;nbsp;96.53&lt;BR /&gt;C669&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.50&amp;nbsp; &amp;nbsp;196&amp;nbsp; &amp;nbsp;97.03&lt;BR /&gt;C672&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.99&amp;nbsp; &amp;nbsp;198&amp;nbsp; &amp;nbsp;98.02&lt;BR /&gt;C674&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0.50&amp;nbsp; &amp;nbsp; 199&amp;nbsp; &amp;nbsp;98.51&lt;BR /&gt;C678&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 0.99&amp;nbsp; &amp;nbsp; 201&amp;nbsp; &amp;nbsp;99.50&lt;BR /&gt;C679&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0.50&amp;nbsp; &amp;nbsp; 202&amp;nbsp; &amp;nbsp;100.00&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This text representation of your data set isn't really specific enough for debugging. Can you provide the data set following these instructions:&amp;nbsp;&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" rel="noopener"&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;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also your code has lots of variables that are not shown in this small data set. Please explain further.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 18:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572471#M161546</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-10T18:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: If/then with missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572476#M161548</link>
      <description>&lt;P&gt;Why do you read the same observation from&amp;nbsp;&lt;SPAN&gt;demog_crstar_pt_level three times in each iteration of the data step? Because that's what the three set statements do in this code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.demog_crstar_pt_level_final;
set work.demog_crstar_pt_level;
if first_dx = ' ' then first_dx = topography_code;
set work.demog_crstar_pt_level; /* any change to first_dx will be reversed by this */
if first_dx_desc = ' ' then first_dx_desc = topography_code_desc;
set work.demog_crstar_pt_level; /* any change to first_dx_desc will be reversed by this */
if first_dx_date = . then first_dx_date = date_of_diagnosis;
/* only this last change will have an effect */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Please supply usable example data from your dataset in a data step with datalines.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 18:48:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572476#M161548</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-10T18:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: If/then with missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572481#M161549</link>
      <description>&lt;P&gt;I was showing the results of a frequency to illustrate my point that their are missing data that I should be able to write code to capture. That is why their are variable in my code that you do not see. Thank you for the input&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 19:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572481#M161549</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2019-07-10T19:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: If/then with missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572482#M161550</link>
      <description>&lt;P&gt;Removing the multiple set statements corrected my problem. Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 19:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572482#M161550</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2019-07-10T19:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: If/then with missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572546#M161575</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;Methinks you should mark the post by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;as a solution since it pinpoints the problem and suggests a way to eliminate it: Your extraneous SET statements cause the conditional assignments to change the assigned values. In other words, you should get rid of all the SET statements but the very first, and then the code should work.&amp;nbsp; Also, you can somewhat streamline and homogenize your code by&amp;nbsp;using the MISSING or CMISS function insensitive to the data type&amp;nbsp;instead of testing for type-specific missing value literals, for example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.demog_crstar_pt_level_final ;                               
  set work.demog_crstar_pt_level;                                     
  if cmiss (first_dx     ) then first_dx      = topography_code ;     
  if cmiss (first_dx_desc) then first_dx_desc = topography_code_desc ;
  if cmiss (first_dx_date) then first_dx_date = date_of_diagnosis ;   
run ;                                                                 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please do NOT mark my post as a solution - it belongs to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 22:08:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572546#M161575</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-07-10T22:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: If/then with missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572547#M161576</link>
      <description>&lt;P&gt;Actually no need for IF statements at all. Just use the COALESCE() function. Of it the variables are character then use the COALESCEC() function.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 22:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572547#M161576</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-10T22:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: If/then with missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572559#M161580</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;True. However, the need to use two functions depending on the data type makes code more error-prone and less robust. IF is a small penalty for the data type insensitivity of CMISS or MISSING. On the other hand, if SQL were used instead, where COALESCE is type insensitive, I'd more than agree that using it would be preferable to using the CASE clause.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 23:02:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-with-missing-data/m-p/572559#M161580</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-07-10T23:02:45Z</dc:date>
    </item>
  </channel>
</rss>

