<?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 IF THEN in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/IF-THEN/m-p/74071#M21456</link>
    <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
I have DATE as character variable (length 9) in the dataset "now_char" and the DATE column has dates like :- 22JAN2010  . I use the code:--&lt;BR /&gt;
&lt;BR /&gt;
data combine;&lt;BR /&gt;
set now_char;&lt;BR /&gt;
	if DATE LT "07JAN2010" THEN		&lt;BR /&gt;
			Week = "Week1";&lt;BR /&gt;
	ELSE IF DATE GT "07/01/08" AND DATE LT "15/01Jan/08" THEN&lt;BR /&gt;
		    Week = "Week2";&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
Log:-&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).&lt;BR /&gt;
      760:16   762:21   762:43&lt;BR /&gt;
NOTE: Invalid numeric data, '27JAN2008' , at line 760 column 16.&lt;BR /&gt;
NOTE: Invalid numeric data, '26/01/08' , at line 762 column 21.&lt;BR /&gt;
NOTE: Invalid numeric data, '31/01Jan/08' , at line 762 column 43.&lt;BR /&gt;
&lt;BR /&gt;
Any suggestions?&lt;BR /&gt;
&lt;BR /&gt;
Kindest Regards,&lt;BR /&gt;
Kriti</description>
    <pubDate>Wed, 22 Sep 2010 19:14:06 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-09-22T19:14:06Z</dc:date>
    <item>
      <title>IF THEN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/IF-THEN/m-p/74071#M21456</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
I have DATE as character variable (length 9) in the dataset "now_char" and the DATE column has dates like :- 22JAN2010  . I use the code:--&lt;BR /&gt;
&lt;BR /&gt;
data combine;&lt;BR /&gt;
set now_char;&lt;BR /&gt;
	if DATE LT "07JAN2010" THEN		&lt;BR /&gt;
			Week = "Week1";&lt;BR /&gt;
	ELSE IF DATE GT "07/01/08" AND DATE LT "15/01Jan/08" THEN&lt;BR /&gt;
		    Week = "Week2";&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
Log:-&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).&lt;BR /&gt;
      760:16   762:21   762:43&lt;BR /&gt;
NOTE: Invalid numeric data, '27JAN2008' , at line 760 column 16.&lt;BR /&gt;
NOTE: Invalid numeric data, '26/01/08' , at line 762 column 21.&lt;BR /&gt;
NOTE: Invalid numeric data, '31/01Jan/08' , at line 762 column 43.&lt;BR /&gt;
&lt;BR /&gt;
Any suggestions?&lt;BR /&gt;
&lt;BR /&gt;
Kindest Regards,&lt;BR /&gt;
Kriti</description>
      <pubDate>Wed, 22 Sep 2010 19:14:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/IF-THEN/m-p/74071#M21456</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-22T19:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/IF-THEN/m-p/74072#M21457</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
The easiest solution is to convert the character data (which is just a piece of text) into a SAS date (the number of days since 01JAN1960). To do this you need something like:&lt;BR /&gt;
&lt;BR /&gt;
data combine;&lt;BR /&gt;
  set now_char;&lt;BR /&gt;
  if input(date,date9.) lt "07JAN2010"d then week = "Week1";&lt;BR /&gt;
  else if ....;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Note that the d following the date in quotes inputes the text as a SAS date ("07JAN2010"d). I would have wrote out the whole data step but the dates in the second category don't appear to make any sense.&lt;BR /&gt;
&lt;BR /&gt;
Hope that helps</description>
      <pubDate>Wed, 22 Sep 2010 19:45:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/IF-THEN/m-p/74072#M21457</guid>
      <dc:creator>Proc_explode</dc:creator>
      <dc:date>2010-09-22T19:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/IF-THEN/m-p/74073#M21458</link>
      <description>I'm not sure what you are trying to do.  If it is simply to count the number of seven day periods since January 1 of a given year, you could use something like:&lt;BR /&gt;
&lt;BR /&gt;
data combine; &lt;BR /&gt;
  set now_char;&lt;BR /&gt;
  week=intck(cats('week.',&lt;BR /&gt;
   weekday(mdy(1,1,year(input(date,date9.))))),&lt;BR /&gt;
           mdy(1,1,year(input(date,date9.))),&lt;BR /&gt;
           input(date,date9.))+1;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art</description>
      <pubDate>Wed, 22 Sep 2010 22:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/IF-THEN/m-p/74073#M21458</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2010-09-22T22:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/IF-THEN/m-p/74074#M21459</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Code and notes do not match&lt;BR /&gt;
Notes say '27JAN2008' that can't be found in code.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column) 760:16 762:21 762:43&lt;BR /&gt;
Look in your log, if you see something like 760 if DATE LT "..." THEN &lt;BR /&gt;
It means your DATE is not a character variable&lt;BR /&gt;
&lt;BR /&gt;
HTH</description>
      <pubDate>Thu, 23 Sep 2010 08:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/IF-THEN/m-p/74074#M21459</guid>
      <dc:creator>tlt</dc:creator>
      <dc:date>2010-09-23T08:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/IF-THEN/m-p/74075#M21460</link>
      <description>While I still don't know what you are trying to accomplish, I hadn't payed enough attention to the notes you indicated were in the SAS log.&lt;BR /&gt;
&lt;BR /&gt;
Since your dates have an odd mixture of formats, again only if I correctly understand the problem, you might try something like:&lt;BR /&gt;
&lt;BR /&gt;
data now_char;&lt;BR /&gt;
  input date $11.;&lt;BR /&gt;
  cards;&lt;BR /&gt;
27JAN2008&lt;BR /&gt;
26/01/08&lt;BR /&gt;
31/01Jan/08&lt;BR /&gt;
;&lt;BR /&gt;
options datestyle=dmy;&lt;BR /&gt;
data combine;&lt;BR /&gt;
  set now_char;&lt;BR /&gt;
  if anyalpha(scan(date,2))*anydigit(scan(date,2)) then&lt;BR /&gt;
    date=compress(date,,"a");&lt;BR /&gt;
  format date2 date9.;&lt;BR /&gt;
  date2=input(date,anydtdte11.);&lt;BR /&gt;
  week=intck(cats('week.',&lt;BR /&gt;
    weekday(mdy(1,1,year(input(date,anydtdte11.))))),&lt;BR /&gt;
    mdy(1,1,year(input(date,anydtdte11.))),&lt;BR /&gt;
    input(date,anydtdte11.))+1;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art</description>
      <pubDate>Thu, 23 Sep 2010 12:26:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/IF-THEN/m-p/74075#M21460</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2010-09-23T12:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/IF-THEN/m-p/74076#M21461</link>
      <description>Hi  Kriti&lt;BR /&gt;
&lt;BR /&gt;
That looks like code you have written, so just re-write it a little differently&lt;BR /&gt;
"07JAN2010" is a character constant&lt;BR /&gt;
"07JAN2010"d is a date constant&lt;BR /&gt;
However, if your data "work.now_char" holds variable "date" as a character variable, your code will have to "interpret" it as a date to use relative tests like GT or LE..... not very different&lt;BR /&gt;
First since you refer to "DATE" more than once, convert it to a sas date, just once like:&lt;BR /&gt;
  sas_date = input(DATE, date9.) ;&lt;BR /&gt;
&lt;BR /&gt;
Your data step would adapt simply like:&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; data combine;&lt;BR /&gt;
&amp;gt; set now_char;&lt;BR /&gt;
  sas_date = input(DATE, date9.) ;&lt;BR /&gt;
&lt;BR /&gt;
  	if sas_DATE  LT "07JAN2010"d THEN&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt;			Week = "Week1";&lt;BR /&gt;
&lt;BR /&gt;
  ELSE IF sas_DATE GT "07Jan08"d AND sas_DATE LT "15Jan08"d&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt;  THEN&lt;BR /&gt;
&amp;gt; 		    Week = "Week2";&lt;BR /&gt;
&amp;gt; RUN;&lt;BR /&gt;
 &lt;BR /&gt;
does that explain what you need?&lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
      <pubDate>Fri, 24 Sep 2010 16:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/IF-THEN/m-p/74076#M21461</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-09-24T16:10:55Z</dc:date>
    </item>
  </channel>
</rss>

