Hi,
Happy new year to all!
Can someone help me out in fixing the error in this process?
data EVComplaints2;
set EVComplaints;
format EV_Week mmddyy. receipt_date2 mmddyy.;
receipt_date2 = input(receipt_date, mmddyy10.);
orig_month = month(receipt_date2);
orig_year = year(receipt_date2);
EV_Week = intnx('week',receipt_date2,0);
if orig_month >= 10 then EV_Month_Year = strip(orig_month)||'-'||strip(orig_year);
else EV_Month_Year = '0'||strip(orig_month)||'-'||strip(orig_year);
run;
Below is the error I am getting when I ran the above process:
NOTE: Argument 2 to function INTNX('week',.,0) at line 31 column 11 is invalid.
Receipt Date=10/17/2018 10:56 PM Location=96 EV_Week=. receipt_date2=. receipt_date=. orig_month=. orig_year=. EV_Month_Year=0.-.
_ERROR_=1 _N_=1
the output from the process is this:
Receipt Date | Location | EV_Week | receipt_date2 | receipt_date | orig_month | orig_year | EV_Month_Year |
10/17/2018 22:56 | 96 | . | . | . | . | . | 0.-. |
10/18/2018 21:53 | 96 | . | . | . | . | . | 0.-. |
10/25/2018 23:34 | 96 | . | . | . | . | . | 0.-. |
11/14/2018 23:00 | 96 | . | . | . | . | . | 0.-. |
11/28/2018 21:39 | 96 | . | . | . | . | . | 0.-. |
11/28/2018 21:59 | 96 | . | . | . | . | . | 0.-. |
11/28/2018 22:24 | 96 | . | . | . | . | . | 0.-. |
THANK YOU IN ADVANCE 🙂
Try changing to
if receipt_date2>. then EV_Week = intnx('week',receipt_date2,0);
Thanks for the suggestion, however it gave me blank data when I ran it.
Are your date variables - date values or datetime values?
Do you expect missing values in them?
if datetime, you could try
if receipt_date2>. then EV_Week = intnx('dtweek',receipt_date2,0);
I am assuming your data values are numeric values and not character. Run a proc contents to determine correctly
Or the post the text file and your requirement, let me code it for you
Thanks, below is the data source
Receipt Date | Location |
10/17/2018 22:56 | 96 |
10/18/2018 21:53 | 96 |
10/25/2018 23:34 | 96 |
11/14/2018 23:00 | 96 |
11/28/2018 21:39 | 96 |
Hi - it's datetime values
I'm expecting an output like below:
Receipt Date | Location | EV_Week | receipt_date2 | orig_month | orig_year | EV_Month_Year |
10/17/2018 22:56 | 96 | 10/14/18 | 10/17/18 | 10 | 2018 | 10-2018 |
10/18/2018 21:53 | 96 | 10/14/18 | 10/18/18 | 10 | 2018 | 10-2018 |
10/25/2018 23:34 | 96 | 10/21/18 | 10/25/18 | 10 | 2018 | 10-2018 |
11/14/2018 23:00 | 96 | 11/11/18 | 11/14/18 | 11 | 2018 | 11-2018 |
11/28/2018 21:39 | 96 | 11/25/18 | 11/28/18 | 11 | 2018 | 11-2018 |
11/28/2018 21:59 | 96 | 11/25/18 | 11/28/18 | 11 | 2018 | 11-2018 |
11/28/2018 22:24 | 96 | 11/25/18 | 11/28/18 | 11 | 2018 | 11-2018 |
Ok,
data EVComplaints;
infile cards truncover;
input Receipt_Date anydtdtm21.;
format Receipt_Date datetime20.;
cards;
10/17/2018 22:56
10/18/2018 21:53
10/25/2018 23:34
11/14/2018 23:00
11/28/2018 21:39
11/28/2018 21:59
11/28/2018 22:24
;
run;
data EVComplaints2;
set EVComplaints;
format EV_Week mmddyy. receipt_date2 mmddyy.;
receipt_date2 = datepart(Receipt_Date);
orig_month = month(receipt_date2);
orig_year = year(receipt_date2);
if receipt_date2>. then EV_Week = intnx('week',receipt_date2,0);
if orig_month >= 10 then EV_Month_Year = catx('-',orig_month,orig_year);
else EV_Month_Year = catx('-','0',orig_month,orig_year);
run;
proc print noobs;run;
SAS Output
The SAS System |
Receipt_Date | EV_Week | receipt_date2 | orig_month | orig_year | EV_Month_Year |
---|---|---|---|---|---|
17OCT2018:22:56:00 | 10/14/18 | 10/17/18 | 10 | 2018 | 10-2018 |
18OCT2018:21:53:00 | 10/14/18 | 10/18/18 | 10 | 2018 | 10-2018 |
25OCT2018:23:34:00 | 10/21/18 | 10/25/18 | 10 | 2018 | 10-2018 |
14NOV2018:23:00:00 | 11/11/18 | 11/14/18 | 11 | 2018 | 11-2018 |
28NOV2018:21:39:00 | 11/25/18 | 11/28/18 | 11 | 2018 | 11-2018 |
28NOV2018:21:59:00 | 11/25/18 | 11/28/18 | 11 | 2018 | 11-2018 |
28NOV2018:22:24:00 | 11/25/18 | 11/28/18 | 11 | 2018 | 11-2018 |
@Eugenio21 Sorry I missed to the variable location in the previous
Here you go,
data EVComplaints;
infile cards truncover;
input Receipt_Date & anydtdtm21. Location ;
format Receipt_Date datetime20.;
cards;
10/17/2018 22:56 96
10/18/2018 21:53 96
10/25/2018 23:34 96
11/14/2018 23:00 96
11/28/2018 21:39 96
;
run;
data EVComplaints2;
set EVComplaints;
format EV_Week mmddyy. receipt_date2 mmddyy.;
receipt_date2 = datepart(Receipt_Date);
orig_month = month(receipt_date2);
orig_year = year(receipt_date2);
if receipt_date2>. then EV_Week = intnx('week',receipt_date2,0);
if orig_month >= 10 then EV_Month_Year = catx('-',orig_month,orig_year);
else EV_Month_Year = catx('-','0',orig_month,orig_year);
run;
proc print noobs;run;
SAS Output
The SAS System |
Receipt_Date | Location | EV_Week | receipt_date2 | orig_month | orig_year | EV_Month_Year |
---|---|---|---|---|---|---|
17OCT2018:22:56:00 | 96 | 10/14/18 | 10/17/18 | 10 | 2018 | 10-2018 |
18OCT2018:21:53:00 | 96 | 10/14/18 | 10/18/18 | 10 | 2018 | 10-2018 |
25OCT2018:23:34:00 | 96 | 10/21/18 | 10/25/18 | 10 | 2018 | 10-2018 |
14NOV2018:23:00:00 | 96 | 11/11/18 | 11/14/18 | 11 | 2018 | 11-2018 |
28NOV2018:21:39:00 | 96 | 11/25/18 | 11/28/18 | 11 | 2018 | 11-2018 |
Hi,
the data source is a proc import process. There is an excel spreadsheet that I imported and from there is where my datetime values are coming from.
do I have to put in all the datetime values from that import as cards?
thanks.
below is the actual process:
PROC IMPORT OUT= EVComplaints
DATAFILE= "Daily Reporting\Customer Feedback\Q4 2018 Escalated Customer Complaints"
DBMS=xls REPLACE;
Sheet=Sheet1;
GETNAMES=YES;
RUN;
data EVComplaints2;
set EVComplaints;
format EV_Week mmddyy. receipt_date2 mmddyy.;
receipt_date2 = datepart(receipt_date);
orig_month = month(receipt_date2);
orig_year = year(receipt_date2);
EV_Week = intnx('week',receipt_date2,0);
if orig_month >= 10 then EV_Month_Year = strip(orig_month)||'-'||strip(orig_year);
else EV_Month_Year = '0'||strip(orig_month)||'-'||strip(orig_year);
run;
I generally refrain using proc import coz I hate letting SAS making guesses. Nevertheless, if your proc import is successfull that read the values correctly, you are fine.
And I suppose you may have validated what proc import did(hopefully right). If yes, just run the second step. The cards step was just a sample I created to have something to test in my local.
If for any reason, proc import didn't read properly, switch to datastep with infile and input. Specify the path in infile statement and read it. Cards is just reading data instream for simple tests, not for production code/environment.
NOTE: The 2nd step is the actual solution/answer
@Eugenio21 wrote:
Hi,
the data source is a proc import process. There is an excel spreadsheet that I imported and from there is where my datetime values are coming from.
do I have to put in all the datetime values from that import as cards?
thanks.
No, you do not. That's what @novinosrin was doing to generate sample data to test his code, you can use just the next step, the data step that processes the imported data.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.