## Number into date

Occasional Contributor
Posts: 12

# Number into date

hi, i use sas 9.4

i got the following 2 Columns: year and day.

year is 2008.

day: 1 to 322.

1 means 1.1.2008 and so on...

how do i convert the numbers ito dates?

super urgent!! thanxxx

PROC Star
Posts: 8,163

## Re: Number into date

You showed what day=1 looks like. What should day=322 look like?

Art, CEO, AnalystFinder.com

Occasional Contributor
Posts: 12

## Re: Number into date

Day 1 looks like '1' (means 1.1.2008),
Day 322 looks like '322'...
PROC Star
Posts: 8,163

## Re: Number into date

Ok. Day 322 looks like '322', but means? ....

Does it mean the 322nd day of the year? Plus you said that it looks like '322'. Is that the number 322, or a character string?

Art, CEO, AnalystFinder.com

Posts: 1,837

## Re: Number into date

Assuming day is the sequential day in a year, you can calculatr the date as:

date = mdy(1,1,year) + day -1;

format day ddmmyy10. ;   /* or any other date format, e.g date9. */

taht is, for year=2008 then date = Jan 1st, 2008 + day - 1;

Occasional Contributor
Posts: 12

## Re: Number into date

Number- 322
Occasional Contributor
Posts: 12

Ok,i will try
Thanxxx
Posts: 1,837

## Re: Number into date

If you have the year and the day input as yyyyddd

then you can also use:

``````data _NULL_;
date_in = '2016055';    /*year=2016 day=055 */
date = input(date_in, julian7.);  /* Julian date informat */
put date date9.;       /* check date in log */
run;``````
Occasional Contributor
Posts: 12

## Re: Number into date

What will be the syntax if i have 300+ rows?
Posts: 1,837

## Re: Number into date

Tha synatx depends on your input.

Post a sample of your input file, better as data step to read it,

or maybe:

``````data have;
input date julian7. ;
format date date9.;
datalines;
2008200
2010035
2015106
;
run;``````
Occasional Contributor
Posts: 12

## Re: Number into date

i have +300 rows... in colum 'day' i have number: 1-365, in colum 'year'= 2008.

i want to create anothe colum name 'date'- which will be the xx (from colum 'day') day of the year 2008.

for exemple: if i have the number 4 in 'day' colum, i want that it colum 'date' it will show: 4/1/2008.

Super User
Posts: 8,068

## Re: Number into date

Do you have the data already in a dataset? Or are you reading from a text file?  If you are reading from a text file then the data step would look like this:

``````data want ;
infile 'myfile.txt' ;
input year day ;
date = mdy(1,1,year)+day-1;
format date date9.;
run;``````

If you have an existing SAS dataset then replace the INFILE and INPUT statements with a SET statement.

Occasional Contributor
Posts: 12

## Re: Number into date

i have data in an exel file.

how will the syntax will be?

this way it is not working...

PROC Star
Posts: 8,163

## Re: Number into date

After importing, when you click on the file on SAS, what are the properties of each of those fields? Specifically, we need to know if each is character or numeric.

Art, CEO, AnalystFinder.com

Occasional Contributor
Posts: 12

## Re: Number into date

is this helps?

informat year best32. ;
informat day best32.

Discussion stats
• 20 replies
• 295 views
• 0 likes
• 5 in conversation