BookmarkSubscribeRSS Feed
Eugenio21
Calcite | Level 5

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 DateLocationEV_Weekreceipt_date2receipt_dateorig_monthorig_yearEV_Month_Year
10/17/2018 22:5696.....0.-.
10/18/2018 21:5396.....0.-.
10/25/2018 23:3496.....0.-.
11/14/2018 23:0096.....0.-.
11/28/2018 21:3996.....0.-.
11/28/2018 21:5996.....0.-.
11/28/2018 22:2496.....0.-.

 

 

THANK YOU IN ADVANCE 🙂

12 REPLIES 12
novinosrin
Tourmaline | Level 20

Try changing to

 

if receipt_date2>. then  EV_Week = intnx('week',receipt_date2,0);

 

 

Eugenio21
Calcite | Level 5

Thanks for the suggestion, however it gave me blank data when I ran it.

novinosrin
Tourmaline | Level 20

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

novinosrin
Tourmaline | Level 20

Or the post the text file and your requirement, let me code it for you

Eugenio21
Calcite | Level 5

Thanks,  below is the data source

 

 

Receipt DateLocation
10/17/2018 22:5696
10/18/2018 21:5396
10/25/2018 23:3496
11/14/2018 23:0096
11/28/2018 21:3996
Eugenio21
Calcite | Level 5

Hi - it's datetime values

 

I'm expecting an output like below:

 

Receipt DateLocationEV_Weekreceipt_date2orig_monthorig_yearEV_Month_Year
10/17/2018 22:569610/14/1810/17/1810201810-2018
10/18/2018 21:539610/14/1810/18/1810201810-2018
10/25/2018 23:349610/21/1810/25/1810201810-2018
11/14/2018 23:009611/11/1811/14/1811201811-2018
11/28/2018 21:399611/25/1811/28/1811201811-2018
11/28/2018 21:599611/25/1811/28/1811201811-2018
11/28/2018 22:249611/25/1811/28/1811201811-2018

 

 

novinosrin
Tourmaline | Level 20

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
novinosrin
Tourmaline | Level 20

@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
Eugenio21
Calcite | Level 5

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.

Eugenio21
Calcite | Level 5

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;

novinosrin
Tourmaline | Level 20

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

Reeza
Super User

@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. 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 12 replies
  • 2518 views
  • 0 likes
  • 3 in conversation