<?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 statements based on dates in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/If-statements-based-on-dates/m-p/716806#M27462</link>
    <description>&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;Can this be done in proc sql? or does it not know these times of functions?&lt;/P&gt;</description>
    <pubDate>Thu, 04 Feb 2021 13:28:00 GMT</pubDate>
    <dc:creator>mmea</dc:creator>
    <dc:date>2021-02-04T13:28:00Z</dc:date>
    <item>
      <title>If statements based on dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-statements-based-on-dates/m-p/716801#M27458</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my datastep I want to make a new variable based on a date variable&lt;/P&gt;
&lt;P&gt;Nor a specific date, men a date value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If variable1 HAS a date then new_variable = 1&lt;/P&gt;
&lt;P&gt;If it doesnt have a date the new variable = 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I do so?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 13:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-statements-based-on-dates/m-p/716801#M27458</guid>
      <dc:creator>mmea</dc:creator>
      <dc:date>2021-02-04T13:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: If statements based on dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-statements-based-on-dates/m-p/716802#M27459</link>
      <description>&lt;P&gt;What do you mean by "&lt;SPAN&gt;If variable1 HAS a date" ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I can guess that variable1 is a character variable? So, if the value in variable1 can represent a date, then set new_variable = 1. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Is that right? Can you post come examples of variable1?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 13:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-statements-based-on-dates/m-p/716802#M27459</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-04T13:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: If statements based on dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-statements-based-on-dates/m-p/716803#M27460</link>
      <description>&lt;P&gt;the variable1 has the dates "2020-12-29" etc.&lt;/P&gt;
&lt;P&gt;But can also contain "NULL"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a data step I want to make a new variable (new_variable) that has the values 1 if variable 1 has a date or 0 if variable1 has no date&lt;/P&gt;
&lt;P&gt;make sense?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 13:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-statements-based-on-dates/m-p/716803#M27460</guid>
      <dc:creator>mmea</dc:creator>
      <dc:date>2021-02-04T13:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: If statements based on dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-statements-based-on-dates/m-p/716804#M27461</link>
      <description>&lt;P&gt;The logic here is: If variable1 can meaningfully be represented as a date, set new_varaible to 1. Else set new_variable to 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input variable1 $12.;
datalines;
01/01/2021  
nonsense    
32/01/2021  
somechar    
31/01/2021  
nonsense    
01jan2021   
somechar    
;

data want;
   set have;
   new_variable = input(variable1, anydtdte12.) &amp;gt; .;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;variable1   new_variable 
01/01/2021  1
nonsense    0 
32/01/2021  0 
somechar    0 
31/01/2021  1 
nonsense    0 
01jan2021   1 
somechar    0 
&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Feb 2021 13:22:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-statements-based-on-dates/m-p/716804#M27461</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-04T13:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: If statements based on dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-statements-based-on-dates/m-p/716806#M27462</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;Can this be done in proc sql? or does it not know these times of functions?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 13:28:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-statements-based-on-dates/m-p/716806#M27462</guid>
      <dc:creator>mmea</dc:creator>
      <dc:date>2021-02-04T13:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: If statements based on dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-statements-based-on-dates/m-p/716807#M27463</link>
      <description>&lt;P&gt;Proc SQL is no problem&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input variable1 $12.;
datalines;
01/01/2021  
nonsense    
32/01/2021  
somechar    
31/01/2021  
nonsense    
01jan2021   
somechar    
;

proc sql;
   select variable1,
          (input(variable1, anydtdte12.) &amp;gt; .) as new_variable
   from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Feb 2021 13:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-statements-based-on-dates/m-p/716807#M27463</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-04T13:30:41Z</dc:date>
    </item>
  </channel>
</rss>

