Prev: sum by every n rows.
Next: PHREG w/ strata question
From: mark on 4 Mar 2010 08:20 Hello All, I want to use to assign 4 variables and then obtain a PROC FREQ for the four week variables.For this , I used the code which gives me log error : data week; set sales; IF DateofSale > '01/11/2009' and DateofSale <= '07/11/2009' THEN Week = Week1; Else IF DateofSale >= '08/11/2009' and DateofSale <= '14/11/2009' Week = Week2; Else IF DateofSale > '14/11/2009' and DateofSale <= '21/11/2009' Week = Week3; ELSE IF DateofSale > '21/11/2009' and DateofSale <= '28/11/2009' Week = Week4; Proc Print data = week; Run; Log error :- ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=. ERROR 160-185: No matching IF-THEN clause. NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 342:44 342:58 344:43 344:57 346:43 346:57 NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.WEEK may be incomplete. When this step was stopped there were 0 observations and 11 variables. WARNING: Data set WORK.WEEK was not replaced because this step was stopped. Kindly guide. regards , mark
From: FPAStatman on 4 Mar 2010 10:06 On Mar 4, 6:20 am, mark <mark.chas...(a)yahoo.in> wrote: > Hello All, > > I want to use to assign 4 variables and then obtain a PROC FREQ for > the four week variables.For this , I used the code which gives me log > error : > > data week; > set sales; > IF DateofSale > '01/11/2009' and DateofSale <= '07/11/2009' THEN > Week = Week1; > Else IF DateofSale >= '08/11/2009' and DateofSale <= '14/11/2009' > Week = Week2; > Else IF DateofSale > '14/11/2009' and DateofSale <= '21/11/2009' > Week = Week3; > ELSE IF DateofSale > '21/11/2009' and DateofSale <= '28/11/2009' > Week = Week4; > Proc Print data = week; > Run; > > Log error :- > > ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, > *, **, +, -, /, ;, <, <=, <>, > =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, > NG, NL, NOTIN, OR, ^=, |, ||, > ~=. > > ERROR 160-185: No matching IF-THEN clause. > > NOTE: Character values have been converted to numeric values at the > places given by: (Line):(Column). > 342:44 342:58 344:43 344:57 346:43 346:57 > NOTE: The SAS System stopped processing this step because of errors. > WARNING: The data set WORK.WEEK may be incomplete. When this step was > stopped there were 0 > observations and 11 variables. > WARNING: Data set WORK.WEEK was not replaced because this step was > stopped. > > Kindly guide. > > regards , > mark You forgot some THENs data week; set sales; IF DateofSale > '01/11/2009' and DateofSale <= '07/11/2009' THEN Week = Week1; Else IF DateofSale >= '08/11/2009' and DateofSale <= '14/11/2009' THEN Week = Week2; Else IF DateofSale > '14/11/2009' and DateofSale <= '21/11/2009' THEN Week = Week3; ELSE IF DateofSale > '21/11/2009' and DateofSale <= '28/11/2009' THEN Week = Week4; Proc Print data = week; Run;
From: Nathaniel Wooding on 4 Mar 2010 11:58 Mark In addition to the FPA's comments, you have a major problem with the way that you are using dates. The values that you are showing are simply, to sas, words or, if you will, character strings. They have no relationship to calendar days. Try running the following code: Data CharDates; input Char_date $12. @1 NUMDATE DDMMYY10.; FORMAT NUMDATE WORDDATE15.; SASDATE = NUMDATE ; CARDS; 01/11/2999 07/11/2009 08/11/2009 14/11/2009 14/11/2009 21/11/2009 21/11/1999 28/11/2009 RUN; PROC SORT; BY CHAR_DATE; PROC PRINT;RUN; You will see that I changed the first date to the year 2999 and one towards the end to 1999. I read these in two ways: the first as a string and the second as a SAS date value. When I sorted by Char_Date, the sort was done first, by the value of the first column, then but the value of the second column and so forth. Hence, the value for the year 2999 appears fist in the sorted list. If I were to use these in an if statement, they would be treated in the same manner. Now, note that I read in the variable NUMDATE. The informat ddmmyy10. Tells SAS that I am reading a date and tells it the type of date that we are reading. Internally, SAS stores this value as the number of days since Jan 1, 1960. I gave the variable the format Worddate15. So SAS prints this value with an abbreviation of the name of the month followed by the day any year. There are many different formats. I just chose this by chance. I also created a variable called SASDATE and set it to the value of numdate but did not give it a format. Hence in the printout, you see the actual way that the value is stored. While you may be lucky and have chardates that just happen to meet your if statement criteria , it would be a fluke. You really need to read these as sasdates. Then, you need to write your if statements along the lines of IF DateofSale > '01/11/2009'D and DateofSale <= '07/11/2009'D THEN Week = Week1; Please note the D following the last apostrophe. This tells SAS that you are defining a "date literal" and to treat the value inside the quotes as a SAS date value. Nat Wooding -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of FPAStatman Sent: Thursday, March 04, 2010 10:06 AM To: SAS-L(a)LISTSERV.UGA.EDU Subject: Re: IF-THEN On Mar 4, 6:20 am, mark <mark.chas...(a)yahoo.in> wrote: > Hello All, > > I want to use to assign 4 variables and then obtain a PROC FREQ for > the four week variables.For this , I used the code which gives me log > error : > > data week; > set sales; > IF DateofSale > '01/11/2009' and DateofSale <= '07/11/2009' THEN > Week = Week1; > Else IF DateofSale >= '08/11/2009' and DateofSale <= '14/11/2009' > Week = Week2; > Else IF DateofSale > '14/11/2009' and DateofSale <= '21/11/2009' > Week = Week3; > ELSE IF DateofSale > '21/11/2009' and DateofSale <= '28/11/2009' > Week = Week4; > Proc Print data = week; > Run; > > Log error :- > > ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, > *, **, +, -, /, ;, <, <=, <>, > =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, > NG, NL, NOTIN, OR, ^=, |, ||, > ~=. > > ERROR 160-185: No matching IF-THEN clause. > > NOTE: Character values have been converted to numeric values at the > places given by: (Line):(Column). > 342:44 342:58 344:43 344:57 346:43 346:57 > NOTE: The SAS System stopped processing this step because of errors. > WARNING: The data set WORK.WEEK may be incomplete. When this step was > stopped there were 0 > observations and 11 variables. > WARNING: Data set WORK.WEEK was not replaced because this step was > stopped. > > Kindly guide. > > regards , > mark You forgot some THENs data week; set sales; IF DateofSale > '01/11/2009' and DateofSale <= '07/11/2009' THEN Week = Week1; Else IF DateofSale >= '08/11/2009' and DateofSale <= '14/11/2009' THEN Week = Week2; Else IF DateofSale > '14/11/2009' and DateofSale <= '21/11/2009' THEN Week = Week3; ELSE IF DateofSale > '21/11/2009' and DateofSale <= '28/11/2009' THEN Week = Week4; Proc Print data = week; Run; CONFIDENTIALITY NOTICE: This electronic message contains information which may be legally confidential and or privileged and does not in any case represent a firm ENERGY COMMODITY bid or offer relating thereto which binds the sender without an additional express written confirmation to that effect. The information is intended solely for the individual or entity named above and access by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, distribution, or use of the contents of this information is prohibited and may be unlawful. If you have received this electronic transmission in error, please reply immediately to the sender that you have received the message in error, and delete it. Thank you.
|
Pages: 1 Prev: sum by every n rows. Next: PHREG w/ strata question |