<?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: Proc sql return missing value while suppose to have value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-return-missing-value-while-suppose-to-have-value/m-p/903192#M356915</link>
    <description>&lt;P&gt;The fact that fractions of seconds are not displayed by the assigned format does not mean they're not there.&lt;/P&gt;</description>
    <pubDate>Wed, 15 Nov 2023 13:25:40 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-11-15T13:25:40Z</dc:date>
    <item>
      <title>Proc sql return missing value while suppose to have value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-return-missing-value-while-suppose-to-have-value/m-p/903123#M356882</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;I merge &lt;U&gt;target&lt;/U&gt; file with tic | date | clock_time&amp;nbsp; to ALL with&amp;nbsp;tic| date| clock_time| VOL&amp;nbsp; on tic date clock_time. (of course for this illustration purpose)&lt;/P&gt;
&lt;P&gt;It is so weird that my simple SQL merge below create missing value for VOL for some records while VOL has value in the ALL file.&lt;/P&gt;
&lt;P&gt;I am not sure if it is because of data issue or anything else, so I upload both &lt;U&gt;source&lt;/U&gt; files and the &lt;U&gt;result&lt;/U&gt; file as well as my code so you can see.&lt;/P&gt;
&lt;P&gt;Many thanks,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile='E:\target.xlsx' replace out=target;run;

proc sql;
create table output as select a.*, vol from target as a left join ALL b
on a.tic=b.tic and a.date=b.date and a.clock_time=b.clock_time
order by tic, date, clock_time;
quit;

data missing; set output;
if vol=.;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Print out of missing file. These rows have VOL data in the ALL dataset&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.MISSING" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;tic&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;clock_time&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;date&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;vol&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;A&lt;/TD&gt;
&lt;TD class="r data"&gt;14:33:00&lt;/TD&gt;
&lt;TD class="r data"&gt;14NOV2023&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;A&lt;/TD&gt;
&lt;TD class="r data"&gt;14:34:00&lt;/TD&gt;
&lt;TD class="r data"&gt;14NOV2023&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="l data"&gt;A&lt;/TD&gt;
&lt;TD class="r data"&gt;14:35:00&lt;/TD&gt;
&lt;TD class="r data"&gt;14NOV2023&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="l data"&gt;A&lt;/TD&gt;
&lt;TD class="r data"&gt;14:36:00&lt;/TD&gt;
&lt;TD class="r data"&gt;14NOV2023&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="l data"&gt;A&lt;/TD&gt;
&lt;TD class="r data"&gt;14:37:00&lt;/TD&gt;
&lt;TD class="r data"&gt;14NOV2023&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2023 05:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-return-missing-value-while-suppose-to-have-value/m-p/903123#M356882</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2023-11-15T05:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql return missing value while suppose to have value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-return-missing-value-while-suppose-to-have-value/m-p/903124#M356883</link>
      <description>&lt;P&gt;It would be easier to help you, if you could post the data used. No excel-files, of course, but data steps using datalines. You have checked the log for suspicious messages?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2023 05:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-return-missing-value-while-suppose-to-have-value/m-p/903124#M356883</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-11-15T05:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql return missing value while suppose to have value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-return-missing-value-while-suppose-to-have-value/m-p/903128#M356886</link>
      <description>&lt;P&gt;You left join table ALL that contains your variable Vol to table Target. It appears that for the keys with a missing Vol there is no matching row in your table ALL.&lt;/P&gt;
&lt;P&gt;To test the theory run below code. It should create table test with zero rows.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  set all;
  if tic='A' and date='14NOV2023'd and clock_time='14:33:00't;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And to ensure that the row exists with this exact key (like no decimals for date and time) also cross-check for table Target. Here you should get a row selected.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_2;
  set target;
  if tic='A' and date='14NOV2023'd and clock_time='14:33:00't;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2023 07:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-return-missing-value-while-suppose-to-have-value/m-p/903128#M356886</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-11-15T07:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql return missing value while suppose to have value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-return-missing-value-while-suppose-to-have-value/m-p/903177#M356906</link>
      <description>&lt;P&gt;I see what you meant.&lt;/P&gt;
&lt;P&gt;However, if you open the target file, you can see it has 14:33:00.&lt;/P&gt;
&lt;P&gt;There is no millisecond shown. But when I use the round function to round everything to minute, the SQL works as expected. Still very weird.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data target; set target;
clock_time = round(clock_time,60);
data all; set all;
clock_time = round(clock_time,60);
&lt;/CODE&gt;&lt;/PRE&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;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_2;
  set target;
  if tic='A' and date='14NOV2023'd and '14:32:00't&amp;lt;clock_time&amp;lt;'14:34:00't;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.TEST_2" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;tic&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;clock_time&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;date&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;A&lt;/TD&gt;
&lt;TD class="r data"&gt;14:33:00&lt;/TD&gt;
&lt;TD class="r data"&gt;14NOV2023&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;A&lt;/TD&gt;
&lt;TD class="r data"&gt;14:34:00&lt;/TD&gt;
&lt;TD class="r data"&gt;14NOV2023&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 15 Nov 2023 12:39:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-return-missing-value-while-suppose-to-have-value/m-p/903177#M356906</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2023-11-15T12:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql return missing value while suppose to have value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-return-missing-value-while-suppose-to-have-value/m-p/903192#M356915</link>
      <description>&lt;P&gt;The fact that fractions of seconds are not displayed by the assigned format does not mean they're not there.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2023 13:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-return-missing-value-while-suppose-to-have-value/m-p/903192#M356915</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-11-15T13:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql return missing value while suppose to have value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-return-missing-value-while-suppose-to-have-value/m-p/903233#M356919</link>
      <description>&lt;P&gt;Repeat until nauseated: The formatted display value is not the entire value of the underlying variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Numeric formats as supplied by SAS typically "round" displayed values to fit in a specified or default width.&lt;/P&gt;
&lt;P&gt;If the value is 0.0000000001 and the format is Best12. (default for unassigned numeric variables) you will typically see a displayed value of 1E-10.&lt;/P&gt;
&lt;P&gt;Date formats typically ignore decimal portions of the value as at best that would represent a fraction of a day and is not in the rules for display.&lt;/P&gt;
&lt;P&gt;Time or datetime will display fractions of a second in as many decimal points as &lt;STRONG&gt;you&lt;/STRONG&gt; specify with the format. If there is no such in the format then the fractional seconds are not displayed. And may well be rounded to match specified width.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Custom formats can do some even more amazing things to the values but the match for Join or By values in data step still use the value of the variable, not the formatted value unless you go to some extra steps to force that behavior.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2023 15:42:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-return-missing-value-while-suppose-to-have-value/m-p/903233#M356919</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-11-15T15:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql return missing value while suppose to have value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-return-missing-value-while-suppose-to-have-value/m-p/903400#M356972</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;However, if you open the target file, you can see it has 14:33:00.&lt;/P&gt;
&lt;P&gt;There is no millisecond shown. But when I use the round function to round everything to minute, the SQL works as expected. Still very weird.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There is no milliseconds shown because of the format used to print the values. They can of course still exist as part of the internal value (stored in a numeric variable as count of seconds since midnight).&lt;/P&gt;
&lt;P&gt;Also your Excel source uses potentially a format that doesn't surface fractional seconds. If you export your Excel to a .csv then you should see the values there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below sample code to illustrate what I'm talking about.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.all;
  tic='A';
  date='14NOV2023'd;
  clock_time='14:33:00't;
  format date date9. clock_time time.;
  vol=123;
run;

data work.target;
  tic='A';
  date='14NOV2023'd;
  clock_time='14:33:00't;
  format date date9. clock_time time.;
  output;
  clock_time='14:33:00.0000001't;
  output;
  clock_time='14:33:00.999't;
  output;
run;

proc print data=work.all;run;

proc sql;
  select 
    tic
    ,date
    ,clock_time format=time.
    ,clock_time format=time16.7
    ,clock_time format=best32.
  from target
  ;
quit;


proc sql;
  select 
     a.tic
    ,a.date
    ,round(a.clock_time) as clock_time format=time8.
    ,b.vol
  from work.target a left join work.all b
    on a.tic=b.tic and a.date=b.date and round(a.clock_time)=round(b.clock_time)
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1700096533585.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89893i1CA505F9EF8EFA7A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1700096533585.png" alt="Patrick_0-1700096533585.png" /&gt;&lt;/span&gt;&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>Thu, 16 Nov 2023 01:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-return-missing-value-while-suppose-to-have-value/m-p/903400#M356972</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-11-16T01:04:14Z</dc:date>
    </item>
  </channel>
</rss>

