DATA Step, Macro, Functions and more

problem with sas code

Accepted Solution Solved
Reply
Contributor
Posts: 38
Accepted Solution

problem with sas code

[ Edited ]

Here Date is a set of different dates defined in d_mtcars dataset and I am trying to find the number of days between Date and last_date. But, the values in the days column are missing as output. Please help.

 

data date_mtcars;
set character_mtcars(drop=prefix);
set d_mtcars;

last_date='29july2017';
days= intck ('day',Date,last_date);
run;

proc print data=date_mtcars;
run;

Accepted Solutions
Solution
‎07-03-2017 02:06 AM
Super User
Posts: 19,862

Re: problem with sas code

Posted in reply to atulsingh

Other than the date does the data set appear in the correct format?

 

You need only a 3 character month, you have the full word. 

 

JUL vs JULY

View solution in original post


All Replies
Super User
Posts: 19,862

Re: problem with sas code

Posted in reply to atulsingh

Why do you have 2 SET statements? What are you expecting to happen with those two statements?

Contributor
Posts: 38

Re: problem with sas code

I have combined two datasets using two set statements.

Contributor
Posts: 38

Re: problem with sas code

Posted in reply to atulsingh
please help.
Super User
Posts: 19,862

Re: problem with sas code

Posted in reply to atulsingh

Review how to combine data. I suspect that's your first and probably biggest issue.

http://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#p15jvywi5avt3cn1bee8...

 

Trusted Advisor
Posts: 1,584

Re: problem with sas code

Beyond to @Reeza's comment, relating to combination of datasets,

you have an error defining a date literal. Change line into:

last_date='29july2017'd;

and you can calculate days between dates just by:

days = date - last_date;

no need to use special function.

Contributor
Posts: 38

Re: problem with sas code

data date_mtcars;
set character_mtcars(drop=prefix);
set d_mtcars;
last_date='29july2017'd;
days= intck('day',Date,last_date);
run;
proc print data=date_mtcars;
run;

 

 

After defining date as you said, it's showing error again,

 
ERROR: Invalid date/time/datetime constant '29july2017'd.
ERROR 77-185: Invalid number conversion on '29july2017'd.

 

Solution
‎07-03-2017 02:06 AM
Super User
Posts: 19,862

Re: problem with sas code

Posted in reply to atulsingh

Other than the date does the data set appear in the correct format?

 

You need only a 3 character month, you have the full word. 

 

JUL vs JULY

PROC Star
Posts: 7,492

Re: problem with sas code

Posted in reply to atulsingh

Assuming that date is actually a SAS date, your problem is likely that you defined:

last_date='29july2017';

when you should have used:

last_date='29july2017'd;

Art, CEO, AnalystFinder.com

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 301 views
  • 0 likes
  • 4 in conversation