BookmarkSubscribeRSS Feed
rochka84
Calcite | Level 5

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

 

20 REPLIES 20
art297
Opal | Level 21

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

 

Art, CEO, AnalystFinder.com

 

rochka84
Calcite | Level 5
Day 1 looks like '1' (means 1.1.2008),
Day 322 looks like '322'...
art297
Opal | Level 21

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

Shmuel
Garnet | Level 18

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;

rochka84
Calcite | Level 5
Number- 322
rochka84
Calcite | Level 5
Ok,i will try
Thanxxx
Shmuel
Garnet | Level 18

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;
rochka84
Calcite | Level 5
What will be the syntax if i have 300+ rows?
Shmuel
Garnet | Level 18

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;
rochka84
Calcite | Level 5

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.

 

Tom
Super User Tom
Super User

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.

rochka84
Calcite | Level 5

i have data in an exel file.

how will the syntax will be?

this way it is not working...

art297
Opal | Level 21

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

rochka84
Calcite | Level 5

is this helps?

 

informat year best32. ;
informat day best32.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 20 replies
  • 1356 views
  • 0 likes
  • 5 in conversation