Help using Base SAS procedures

Week()

Reply
N/A
Posts: 0

Week()

I use the code -

data week;
set sales;
week_var = INTCK('WEEK','01/11/2009','07/11/2009');
proc print data = week;
run;

It gives me an error in log-

NOTE: Character values have been converted to numeric values at the places given by: (Line)Smiley SadColumn).
115:27 115:40
NOTE: Invalid numeric data, '01/11/2009' , at line 115 column 27.
NOTE: Invalid numeric data, '07/11/2009' , at line 115 column 40.
TransactionID=RX000152 DateofSale=03/11/2009 TimeofSale=11:27:53 LaptopModel=AP3965 UnitsSold=5


I have monthly data starts from 01/11/2009 and continue till 29/11/2009. I need to get summary data for each week and so have used the week().Kindly suggest the correction in code.

regards ,
markc
Super Contributor
Super Contributor
Posts: 3,174

Re: Week()

Posted in reply to deleted_user
You are attempting to use SAS CHARACTER type variables where the documented expectation is that you are supplying a SAS numeric (date or datetime) variable.

I'm not going to continue to post DOC links and suggestions that go unheeded.

Honestly, to the OP MarkC, you really need to digest and learn from your posts when received and not simply move on to another request from your boss or whatever. It will help drastically with your future SAS programming productivity and effectiveness, if that's your intention and quest.

So, regarding this post: I suggest strongly that you read up on SAS DATE, TIME and DATETIME variables, and also (for this exercise) you will want to pay attention to how to code a SAS DATE literal as an argument to INTCK (and INTNX for that matter).

Scott Barry
SBBWorks, Inc.
Super Contributor
Posts: 292

Re: Week()

Posted in reply to deleted_user
the date strings have to be converted into sas date values for sas to understand them
try
week_var = INTCK('WEEK',input('01/11/2009',date9.),input('07/11/2009',date9.));
Valued Guide
Posts: 765

Re: Week()

hi ... INTCK requires numeric variables as arguments

if you are specifying the dates as literals, express your dates a bit differently and use a date constant ...
[pre]
data _null_;
week_var = INTCK('WEEK', '11jan2009'd , '11jul2009'd);
put "WEEK_VAR: " week_var;
run;

LOG ...
WEEK_VAR: 25
[/pre]
if there's a date already in the data ...
[pre]
data test;
input dt : mmddyy. @@;
week_var = INTCK('WEEK', '11jan2009'd , dt);
format dt mmddyy10.;
datalines;
02/10/2009 03/07/2009 12/15/2009
;
run;

proc print data = test;
run;

OUTPUT ...
Obs dt week_var
1 02/10/2009 4
2 03/07/2009 7
3 12/15/2009 48
[/pre]
Ask a Question
Discussion stats
  • 3 replies
  • 420 views
  • 0 likes
  • 4 in conversation