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

Hello, I have a number that represents the number of days from January 1 of any year with January 1 as day 1. For example 10 will be January 10. 

Using SAS how can I convert that number into day and month for example 10 = 01/10?

 

Thanks.

 

Pramodini

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

OK, it's easy enough to split this in two.  These statements assume that your original variable is numeric.  If it is actually character, the statements would change slightly.

 

year = int(juldateval / 1000);

days = mod(juldateval, 1000);

newdate = mdy(1, 1, year) + days - 1;

format newdate mmddyys10.;

 

 

View solution in original post

8 REPLIES 8
Astounding
PROC Star

How do you intend to supply the year?  Getting the correct answer depends on whether or not it is a leap year.

pr1
Calcite | Level 5 pr1
Calcite | Level 5

I have  1956229 as input field that should translate into 8/16/1956

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Where is the data from?  I mean I can see year=1956 as first four characters, but the rest doesn't make sense and formating as date value is wrong.

pr1
Calcite | Level 5 pr1
Calcite | Level 5

1956229 as a field in which the year is 1956 and 229 is the 229th day of year 1956 that is August 16th which should display as 8/16/1956

Astounding
PROC Star

OK, it's easy enough to split this in two.  These statements assume that your original variable is numeric.  If it is actually character, the statements would change slightly.

 

year = int(juldateval / 1000);

days = mod(juldateval, 1000);

newdate = mdy(1, 1, year) + days - 1;

format newdate mmddyys10.;

 

 

pr1
Calcite | Level 5 pr1
Calcite | Level 5

THANKS!!  that works. 

Ksharp
Super User

There already is a funtion to do that .

 

data _null_;
Xend=datejul(2001001);
put Xend / Xend date9.; 
run;
pr1
Calcite | Level 5 pr1
Calcite | Level 5

Thank You.  Let me try this.

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
  • 8 replies
  • 1185 views
  • 3 likes
  • 4 in conversation