BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Miah
Obsidian | Level 7

I am trying to calculate the difference in days between dates. More specifically between the values of variable Date and January 1, 2000. 

 

Here it is my code and I have attached the data set: 

 

PROC IMPORT OUT= work.NBA
DATAFILE= "/folders/myfolders/NBA60.txt"
DBMS=CSV REPLACE;
DELIMITER=',';
GETNAMES=YES;
RUN;

PROC PRINT DATA=work.NBA;
RUN;

PROC PRINT DATA = NBA;
FORMAT Date WORDDATE. ;
RUN;

DATA NBA;
fecha = intck('day', DATE, "01Jan2000"d);
RUN;

PROC PRINT DATA=NBA;
RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You forgot the SET statement in your data step. 

 

DATA NBA_DURATION;
        set NBA;
	fecha = intck('day', DATE, "01Jan2000"d); 
RUN;

View solution in original post

2 REPLIES 2
Reeza
Super User

You forgot the SET statement in your data step. 

 

DATA NBA_DURATION;
        set NBA;
	fecha = intck('day', DATE, "01Jan2000"d); 
RUN;
Astounding
PROC Star

Your data has some dates before year 2000, and some after.  So when you calculate the difference, which years should show a negative difference and which a positive difference?

 

Your formula calculates the number of days as negative for years after 2000.  It's easy to reverse that, and you don't need any functions to do it:

 

fecha = date - '01jan2000'd;

 

And yes, you do need a SET statement.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 12965 views
  • 3 likes
  • 3 in conversation