<?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: Replacing missing values in the DATA statement that combines multiple data sets in a SET stateme in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-values-in-the-DATA-statement-that-combines/m-p/797133#M255861</link>
    <description>&lt;P&gt;Here's the nature of the "feature" you are observing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any variable that comes from a SAS data set is automatically retained.&amp;nbsp; That applies to URDACT.&amp;nbsp; Even though it doesn't exist on every incoming SAS data set, it does exist.&amp;nbsp; So it gets retained.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you combine several data sets, some containing URDACT and some not, SAS has to decide when to set URDACT to a missing value (overriding this automatic retain feature).&amp;nbsp; So when the SET statement switches from one incoming data set to another, SAS begins with a missing value for URDACT.&amp;nbsp; Then it reads in the data for the next data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the tricky part.&amp;nbsp; When the next incoming data set does not contain URDACT, it has a missing value.&amp;nbsp; The IF/THEN condition is true, and the computation takes place assigning URDACT a nonmissing value.&amp;nbsp; That value now gets retained, so on the next observation from the same data, the retained value is still there and URDACT is no longer missing.&amp;nbsp; So the calculated value just sits there, and repeats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The bottom line:&amp;nbsp; when reading observations from a data set that does not contact URDACT, the software sets URDACT to missing for the first observation only.&amp;nbsp; It does NOT reset URDACT on every observation, just the first one (for each data set).&lt;/P&gt;</description>
    <pubDate>Fri, 18 Feb 2022 03:07:36 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2022-02-18T03:07:36Z</dc:date>
    <item>
      <title>Replacing missing values in the DATA statement that combines multiple data sets in a SET statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-values-in-the-DATA-statement-that-combines/m-p/797112#M255852</link>
      <description>&lt;P&gt;This is something I could just avoid, but I would rather try to understand it.&amp;nbsp; EXAMPLE: The early years of the NHANES data do not calculate a ratio of two variables, but later years do, and it is URDACT.&amp;nbsp; If I try to replace the missing in the DATA when I combine them with the SET statement, I get a single value.&amp;nbsp; If I do the same replacement in a DATA step after the combining, I get the correct results.&amp;nbsp; What logic am I missing?&amp;nbsp; THANKS!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;data alb_cr;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;set dat_.LAB16 dat_.L16_b dat_.L16_c dat_.alb_cr_d /*I removed the names of the rest of the data sets*/... ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;if missing(URDACT) then URDACT=(URXUMA*100/URXUCR);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;proc print data=alb_cr(obs=10); &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;var seqn URDACT;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;data alb_cr;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;set dat_.LAB16 dat_.L16_b dat_.L16_c dat_.alb_cr_d&amp;nbsp; /*I removed the names of the rest of the data sets*/... ;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;data alb_cr;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;set alb_cr;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;if missing(URDACT) then URDACT=(URXUMA*100/URXUCR);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;proc print data=alb_cr(obs=10); &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;var seqn URDACT;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;Obs SEQN URDACT&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;1 2 6.27586&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;2 3 6.27586&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;3 5 6.27586&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;4 6 6.27586&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;5 7 6.27586&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;6 8 6.27586&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;7 9 6.27586&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;8 10 6.27586&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;9 11 6.27586&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;10 12 6.27586&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;Obs SEQN URDACT&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;1 2 6.2759&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;2 3 8.2540&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;3 5 3.5465&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;4 6 4.0323&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;5 7 5.2344&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;6 8 5.0413&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;7 9 4.1379&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;8 10 3.9785&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;9 11 2.6506&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Feb 2022 23:56:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-values-in-the-DATA-statement-that-combines/m-p/797112#M255852</guid>
      <dc:creator>DRNelson</dc:creator>
      <dc:date>2022-02-17T23:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing missing values in the DATA statement that combines multiple data sets in a SET stateme</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-values-in-the-DATA-statement-that-combines/m-p/797113#M255853</link>
      <description>&lt;P&gt;Ideally you would provide example data to demonstrate the problem. LIke "what single value" are you seeing?&lt;/P&gt;
&lt;P&gt;What is the format assigned to URDACT and what does it display when a value is missing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you get the same result for a calculation you need to prove that the values URXUMA and URXUCR are actually different before determining if there is an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do those proc print results look like when you do:&lt;/P&gt;
&lt;PRE&gt;proc print data=alb_cr(obs=10);
var seqn URDACT URXUMA URXUCR;

run;&lt;/PRE&gt;
&lt;P&gt;It is much better to show LOG with the code and notes for a question like this so we can see what actually was run plus the notes that might be generated. Because you are "replacing" the same data set so many times if there is an error (that would show in the log) then the set might not actually be replaced when you think it is. Your comment about "removed data sets" might have a syntax issue that we can't see because of incomplete code and the log might reflect that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do note that both SEQN=2 records have the same value for the calculation barring a rounding difference (one reason to ask about FORMATS assigned to a variable. The code you show, if there weren't any problems, I would expect proc print to show the same number of decimals &lt;STRONG&gt;if the set statement is identical &lt;/STRONG&gt;when using all of those data set. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I haven't worked with NHANES much but I do work with other CDC sponsored data and some of the sets variables might change meaning from year to year as well as coding of values in the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Style comment: Use TITLES with out so we know what we are looking at why it is important. I have to guess that first output.&lt;/P&gt;
&lt;P&gt;It really is a good idea to use RUN; statements.&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>Fri, 18 Feb 2022 00:35:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-values-in-the-DATA-statement-that-combines/m-p/797113#M255853</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-18T00:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing missing values in the DATA statement that combines multiple data sets in a SET stateme</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-values-in-the-DATA-statement-that-combines/m-p/797133#M255861</link>
      <description>&lt;P&gt;Here's the nature of the "feature" you are observing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any variable that comes from a SAS data set is automatically retained.&amp;nbsp; That applies to URDACT.&amp;nbsp; Even though it doesn't exist on every incoming SAS data set, it does exist.&amp;nbsp; So it gets retained.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you combine several data sets, some containing URDACT and some not, SAS has to decide when to set URDACT to a missing value (overriding this automatic retain feature).&amp;nbsp; So when the SET statement switches from one incoming data set to another, SAS begins with a missing value for URDACT.&amp;nbsp; Then it reads in the data for the next data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the tricky part.&amp;nbsp; When the next incoming data set does not contain URDACT, it has a missing value.&amp;nbsp; The IF/THEN condition is true, and the computation takes place assigning URDACT a nonmissing value.&amp;nbsp; That value now gets retained, so on the next observation from the same data, the retained value is still there and URDACT is no longer missing.&amp;nbsp; So the calculated value just sits there, and repeats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The bottom line:&amp;nbsp; when reading observations from a data set that does not contact URDACT, the software sets URDACT to missing for the first observation only.&amp;nbsp; It does NOT reset URDACT on every observation, just the first one (for each data set).&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 03:07:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-values-in-the-DATA-statement-that-combines/m-p/797133#M255861</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-02-18T03:07:36Z</dc:date>
    </item>
  </channel>
</rss>

