Write and run SAS programs in your web browser

Date format

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Date format

Hi,

 

I ve one data set in that the format is YYYY-YYYY, where this is called as reported year.

when i imported to sas studio & after i see it is takeing as Char insted of takeing as date and also i ve used the Code to covert 

i.e, A= input(B,date9.) but still its not in yyyy-yyyy format. is there any other way to make sas to understand it is date format in yyyy-yyyy. can some help me on this to understand this one.

 

Thanks,

Srinidhi

 

 


Accepted Solutions
Solution
‎01-01-2016 12:17 AM
Super User
Super User
Posts: 6,351

Re: Date format

YYYY-YYYY is not a date.  You might think of it as a date range (or what Teradata calls a PERIOD), but SAS does not have a special data type for storing date ranges.

 

You are probably better off leaving it as a character variable. 

 

You could possible store it as two variables, say start_year and end_year. But even then they wouldn't be dates, they would be just years.

 

 

 

View solution in original post


All Replies
Super User
Posts: 1,115

Re: Date format

Hi Srinidhi,

 

I do not think we have a format as yyyy-yyyy, which means there are 2 years concatenated to each other. if i think so. Since it is not a date format we cannot use any date format.

 

Could you please provide an example of the data you have to get better solution.

 

 

Thanks,
Jag
Occasional Contributor
Posts: 5

Re: Date format

Ok fine,
for example
name lunched new car year
BMW 2011-2012
Audi 2012-2013

it will be like this.
Super User
Posts: 1,115

Re: Date format

Thank you for your response. As discussed i am not sure if have a format to read yyyy-yyyy. Is it not fine if you keep the variable in character itself as you could see the years.
Thanks,
Jag
Grand Advisor
Posts: 10,211

Re: Date format

Before considering date formats you should ensure you understand how SAS values dates. Dates are the number of days since 1 January 1960, and always is a specific day. There are SAS supplied formats that display the pieces of data available such a year, month, month day and year in a variety of display formats, year and quarter, week of year, day of week and such.

 

Your value is not a "Date". It may be possible to create a custom format that would treat a single year value such as 2011 so that it would display as "2011-2012" but if you ever run into the "half year" model year for cars introduced at a later part of the annual cycly that approach may not work.

 

How will you use that "model year" value? Will you be doing anything like arithmetic or modeling? It may be better to just use the year introduced instead of 2 years.

 

Solution
‎01-01-2016 12:17 AM
Super User
Super User
Posts: 6,351

Re: Date format

YYYY-YYYY is not a date.  You might think of it as a date range (or what Teradata calls a PERIOD), but SAS does not have a special data type for storing date ranges.

 

You are probably better off leaving it as a character variable. 

 

You could possible store it as two variables, say start_year and end_year. But even then they wouldn't be dates, they would be just years.

 

 

 

Occasional Contributor
Posts: 5

Re: Date format

Thanks Tom..Smiley Happy

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 479 views
  • 3 likes
  • 4 in conversation