<?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: Missing Dates Problems in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70478#M20280</link>
    <description>your example data are not clear:&lt;BR /&gt;
if each PtID will have either one OBS or two OBS and different in year of Date, then you can try this:&lt;BR /&gt;
proc sort data= yourdata;&lt;BR /&gt;
by PtID date;&lt;BR /&gt;
run;&lt;BR /&gt;
data new;&lt;BR /&gt;
set yourdata;&lt;BR /&gt;
by PtID date;&lt;BR /&gt;
year=year(datepart(date));&lt;BR /&gt;
output;&lt;BR /&gt;
if first.date and last.date then do;&lt;BR /&gt;
date=.;&lt;BR /&gt;
value=.; &lt;BR /&gt;
if year =2008 then   year=2009; &lt;BR /&gt;
 else  year=2008; &lt;BR /&gt;
 output;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
but if yourdata contains more OBS for each PtID, you may need simplify your description;</description>
    <pubDate>Wed, 24 Mar 2010 19:19:34 GMT</pubDate>
    <dc:creator>SUN59338</dc:creator>
    <dc:date>2010-03-24T19:19:34Z</dc:date>
    <item>
      <title>Missing Dates Problems</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70473#M20275</link>
      <description>Hello, &lt;BR /&gt;
I want to set some dates to missing. I've tried two ways, based on the documentation below. &lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/onlinedoc/913/getDoc/da/lrcon.hlp/a001292604.htm" target="_blank"&gt;http://support.sas.com/onlinedoc/913/getDoc/da/lrcon.hlp/a001292604.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;First Attempt:&lt;/B&gt;&lt;BR /&gt;
data Pt08;&lt;BR /&gt;
	set LDL0809;&lt;BR /&gt;
	Year = 2008;&lt;BR /&gt;
	if year(datepart(Date)) ne 2008 then Date = . and Value = .;&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Second Attempt:&lt;/B&gt;&lt;BR /&gt;
data Pt09;&lt;BR /&gt;
	set LDL0809;&lt;BR /&gt;
	missing X;&lt;BR /&gt;
	Year = 2009;&lt;BR /&gt;
	if year(datepart(Date)) ne 2009 then Date = X and Value = .;&lt;BR /&gt;
&lt;BR /&gt;
What is happening is that instead of being truly missing, it seems that Date is set to the SAS date value of 0, mean it is showing up as 01JAN1960:00:00:00. &lt;BR /&gt;
&lt;BR /&gt;
If it helps, my goal is that I have a bunch of data where I have the date (Date) and the value of the measurement taken on that date (Value). A Example of the type of data I have:&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;PtID               Date               Value&lt;/U&gt;&lt;BR /&gt;
15                  4/15/08            92&lt;BR /&gt;
15                  5/19/09            106&lt;BR /&gt;
16                  8/12/08            84&lt;BR /&gt;
17                  10/7/09            127&lt;BR /&gt;
&lt;BR /&gt;
However, I need to find the percent of patients for whom a measurement was taken on a yearly basis. So I want to create "missing" dates/values for any year that the measurements were not taken, so that I can work with the data more easily. Like this:&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;PtID               Date               Value          Year&lt;/U&gt;&lt;BR /&gt;
15                  4/15/08            92                  2008&lt;BR /&gt;
15                  5/19/09            106                2009&lt;BR /&gt;
16                  8/12/08            84                  2008&lt;BR /&gt;
16                  .                      .                    2009&lt;BR /&gt;
17                  .                      .                    2008&lt;BR /&gt;
17                  10/7/09            127                2009&lt;BR /&gt;
&lt;BR /&gt;
But, as explained above, anytime I try to set the dates to missing, I get 01JAN1960:00:00:00.&lt;BR /&gt;
&lt;BR /&gt;
What I am missing?!&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Tue, 23 Mar 2010 21:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70473#M20275</guid>
      <dc:creator>AAdams</dc:creator>
      <dc:date>2010-03-23T21:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Dates Problems</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70474#M20276</link>
      <description>Hi:&lt;BR /&gt;
  Your IF statement syntax is incorrect:&lt;BR /&gt;
[pre]&lt;BR /&gt;
if year(datepart(Date)) ne 2008 then Date = . and Value = .;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                     &lt;BR /&gt;
When you use a simple IF statement, you can only perform 1 action as a result of the THEN. So you could do this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
if year(datepart(Date)) ne 2008 then Date = .;&lt;BR /&gt;
if year(datepart(Date)) ne 2008 then Value = .;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                       &lt;BR /&gt;
Or you could do this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
if year(datepart(Date)) ne 2008 then do;&lt;BR /&gt;
    Date = .;&lt;BR /&gt;
    Value = .;&lt;BR /&gt;
end;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                    &lt;BR /&gt;
When you use a DO/END in conjunction with an IF statement, you can execute multiple statements conditionally.&lt;BR /&gt;
 &lt;BR /&gt;
The program below illustrates the wrong way and the right way to code an IF statement. In my test data, all the values for DATE are the same and I am setting variables to missing based on the value of the NAME variable.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
data class;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  date = '15nov1950:07:35:15'dt;&lt;BR /&gt;
              &lt;BR /&gt;
  if name in ('Alfred', 'William', 'Barbara') then do;&lt;BR /&gt;
     date = .;&lt;BR /&gt;
     age = .;&lt;BR /&gt;
     height = .;&lt;BR /&gt;
     weight = .;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
                &lt;BR /&gt;
proc print data=class;&lt;BR /&gt;
  title 'Using IF statement correctly';&lt;BR /&gt;
  format date datetime18.;&lt;BR /&gt;
run;&lt;BR /&gt;
            &lt;BR /&gt;
data badif;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  date = '15nov1950:07:35:15'dt;&lt;BR /&gt;
                 &lt;BR /&gt;
  if name in ('Alfred', 'William', 'Barbara') then &lt;BR /&gt;
     date = . and age = .;&lt;BR /&gt;
run;&lt;BR /&gt;
           &lt;BR /&gt;
proc print data=badif;&lt;BR /&gt;
  title 'Using IF statement incorrectly';&lt;BR /&gt;
  format date datetime18.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 23 Mar 2010 21:21:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70474#M20276</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-03-23T21:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Dates Problems</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70475#M20277</link>
      <description>Thank you!</description>
      <pubDate>Tue, 23 Mar 2010 21:49:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70475#M20277</guid>
      <dc:creator>AAdams</dc:creator>
      <dc:date>2010-03-23T21:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Dates Problems</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70476#M20278</link>
      <description>To complete Cynthia's usually comprehensive answer:&lt;BR /&gt;
&lt;BR /&gt;
 date = .and age = . ;&lt;BR /&gt;
&lt;BR /&gt;
is read by sas as&lt;BR /&gt;
&lt;BR /&gt;
 date = (boolean test);&lt;BR /&gt;
&lt;BR /&gt;
specifically:&lt;BR /&gt;
&lt;BR /&gt;
 date = (. and age = .);&lt;BR /&gt;
&lt;BR /&gt;
since age=. is false, the expression is:&lt;BR /&gt;
&lt;BR /&gt;
(. and 0);&lt;BR /&gt;
&lt;BR /&gt;
which yields 0&lt;BR /&gt;
&lt;BR /&gt;
Try with&lt;BR /&gt;
&lt;BR /&gt;
date = 1 and age ne . ;&lt;BR /&gt;
&lt;BR /&gt;
The boolean test is true and therefore returns 1, and the output is  01JAN60:00:00:01</description>
      <pubDate>Wed, 24 Mar 2010 02:40:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70476#M20278</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2010-03-24T02:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Dates Problems</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70477#M20279</link>
      <description>Thanks, Chris. I meant to put something about boolean expressions in the response, but apparently, the mind-to-screen interface is not yet working.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 24 Mar 2010 03:41:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70477#M20279</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-03-24T03:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Dates Problems</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70478#M20280</link>
      <description>your example data are not clear:&lt;BR /&gt;
if each PtID will have either one OBS or two OBS and different in year of Date, then you can try this:&lt;BR /&gt;
proc sort data= yourdata;&lt;BR /&gt;
by PtID date;&lt;BR /&gt;
run;&lt;BR /&gt;
data new;&lt;BR /&gt;
set yourdata;&lt;BR /&gt;
by PtID date;&lt;BR /&gt;
year=year(datepart(date));&lt;BR /&gt;
output;&lt;BR /&gt;
if first.date and last.date then do;&lt;BR /&gt;
date=.;&lt;BR /&gt;
value=.; &lt;BR /&gt;
if year =2008 then   year=2009; &lt;BR /&gt;
 else  year=2008; &lt;BR /&gt;
 output;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
but if yourdata contains more OBS for each PtID, you may need simplify your description;</description>
      <pubDate>Wed, 24 Mar 2010 19:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70478#M20280</guid>
      <dc:creator>SUN59338</dc:creator>
      <dc:date>2010-03-24T19:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Dates Problems</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70479#M20281</link>
      <description>Hi Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
Re-reading my entry, I realise reading my wording was not very good.&lt;BR /&gt;
&lt;BR /&gt;
I meant "Cynthia's usually comprehensive answer" to mean:&lt;BR /&gt;
&lt;BR /&gt;
- "as usual", as in the opposite of  "Cynthia's unusually comprehensive answer"&lt;BR /&gt;
&lt;BR /&gt;
not to mean:&lt;BR /&gt;
&lt;BR /&gt;
- Cynthia forgot to give half of the answer this once&lt;BR /&gt;
&lt;BR /&gt;
I am sure you didn't take umbrage as you seem such a nice person, but just to make it clear this was meant to be a compliment. Everyone loves and highly regards your knowledgeable and detailed replies here.  &lt;span class="lia-unicode-emoji" title=":monkey_face:"&gt;🐵&lt;/span&gt;</description>
      <pubDate>Wed, 24 Mar 2010 21:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70479#M20281</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2010-03-24T21:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Dates Problems</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70480#M20282</link>
      <description>Chris: &lt;BR /&gt;
Thanks for the clarification. I took your remark as a compliment, really! Thanks! As soon as I saw your post I realized that I'd -thought- of saying something about boolean expressions and had then neglected to actually -type- what I'd thought of. &lt;BR /&gt;
&lt;BR /&gt;
And, I am happy that you like my responses....and that they're useful.&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 25 Mar 2010 02:05:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Missing-Dates-Problems/m-p/70480#M20282</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-03-25T02:05:57Z</dc:date>
    </item>
  </channel>
</rss>

