turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- About SAS dates conversions

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-27-2009 01:32 PM

Only some numerics can be converted to SAS dates directly right? Such as, mmddyy, 040609? You can use format mmddyy8.

But there are special cases where you can't convert them directly and need to go through an extra step rgith? Such as, yyyymmdd, 20090406? You have to convert 20090406 to character using put then convert it to date right?

I just want to make sure if I understand this correctly. Conclusion is that only some numerics can be converted to SAS date directly?

thanks.

But there are special cases where you can't convert them directly and need to go through an extra step rgith? Such as, yyyymmdd, 20090406? You have to convert 20090406 to character using put then convert it to date right?

I just want to make sure if I understand this correctly. Conclusion is that only some numerics can be converted to SAS date directly?

thanks.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-27-2009 01:50 PM

There is the SAS INFORMAT (not format) called ANYDTDTE. which is a bit more forgiving. Here's a sample code snippet to demonstrate:

data _null_;

length cdt $10;

format dt date9.;

cdt = '2005/01/01';

dt = input(cdt,anydtdte10.);

putlog _all_;

/* need to consider YEARCUTOFF= for these */

cdt = '01/01/99';

dt = input(cdt,anydtdte10.);

putlog _all_;

cdt = '1/1/1';

dt = input(cdt,anydtdte10.);

putlog _all_;

run;

Scott Barry

SBBWorks, Inc.

data _null_;

length cdt $10;

format dt date9.;

cdt = '2005/01/01';

dt = input(cdt,anydtdte10.);

putlog _all_;

/* need to consider YEARCUTOFF= for these */

cdt = '01/01/99';

dt = input(cdt,anydtdte10.);

putlog _all_;

cdt = '1/1/1';

dt = input(cdt,anydtdte10.);

putlog _all_;

run;

Scott Barry

SBBWorks, Inc.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-28-2009 10:27 AM

I see. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-27-2009 07:22 PM

You can use the yymmdd8. format for your case.

x='20090406';

date1=input(x, yymmdd8.);

~ Sukanya E

x='20090406';

date1=input(x, yymmdd8.);

~ Sukanya E

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-28-2009 10:27 AM

Thanks. In other words, I can convert any numeric to SAS dates?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-28-2009 11:16 AM

Hi:

Sure, you can convert any -NUMBER- to a SAS date or SAS date/time value, as long as that number either

1) represents the number of days from Jan 1, 1960 (so the number -3334 represents Nov 15, 1950 and the number 3334 is Feb 16, 1969 and the number 18216 is Nov 15, 2009)

or

2) represents the number of seconds from midnight Jan 1, 1960 (date/time value)

However, a NUMERIC variable value like this: 19501115 or a character variable value like this: '19501115' does NOT represent the number of days from Jan 1, 1960 -- so it must be converted from being a number or a character string so that SAS recognizes it as a date variable value and correctly stores your date value as the number of days since Jan 1, 1960.

So when you say "any" numeric, I have to say that the answer is, yes, if you understand SAS date/time values and SAS date/time functions.

cynthia

Sure, you can convert any -NUMBER- to a SAS date or SAS date/time value, as long as that number either

1) represents the number of days from Jan 1, 1960 (so the number -3334 represents Nov 15, 1950 and the number 3334 is Feb 16, 1969 and the number 18216 is Nov 15, 2009)

or

2) represents the number of seconds from midnight Jan 1, 1960 (date/time value)

However, a NUMERIC variable value like this: 19501115 or a character variable value like this: '19501115' does NOT represent the number of days from Jan 1, 1960 -- so it must be converted from being a number or a character string so that SAS recognizes it as a date variable value and correctly stores your date value as the number of days since Jan 1, 1960.

So when you say "any" numeric, I have to say that the answer is, yes, if you understand SAS date/time values and SAS date/time functions.

cynthia

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-28-2009 01:46 PM

hm..i think i need to read the section SAS dates again. I need to tell whether if the number is a qualified number or a number that I need to convert to characters first. Also, Cynthia, how can you be so good with SAS? I see that you reply pretty much every thread here. How can you know everything about SAS? That's amazing! Any book recommendations? Thanks!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-28-2009 09:44 PM

Hi:

Thanks for the compliment. Long ago, (in a galaxy far, far away) I was a Literature student who discovered that there were no good jobs for someone who could deconstruct Faulkner, Melville, Wallace Stevens and T. S. Eliot. And, so I aimed myself at a programmer trainee job; learned Fortran, Cobol, JCL SAS and Easytreve.

But SAS was actually the very first programming language I learned, before the programmer trainee job even started. So when I got the opportunity to be a "real" programmer, one of my choices was to work in the Cobol side of the shop or the "ad-hoc" SAS side of the shop. I chose working on the SAS side of things and have been using SAS ever since.

So it's been a very, -very- long time that I have worked with SAS. I don't know "everything" about SAS -- but I do know how to look things up in the documentation. And, there's the whole puzzle aspect of solving a problem that I find appealing.

My students all speak highly of these authors: Cody, Carpenter, Delwiche/Slaughter, Burlew and Haworth. But there are many other good books available on different topics (For example, I don't teach Stat classes, so I don't know what Stat-related books are most useful.)

The best advice I can give you is learn how to use the resources on support.sas.com -- the search facility, the documentation, the samples and the repository of SAS Global Forum papers. And, don't be afraid to ask yourself "what if" questions and test out your theories or ideas in a test program on sample data.

Good luck!

cynthia

Thanks for the compliment. Long ago, (in a galaxy far, far away) I was a Literature student who discovered that there were no good jobs for someone who could deconstruct Faulkner, Melville, Wallace Stevens and T. S. Eliot. And, so I aimed myself at a programmer trainee job; learned Fortran, Cobol, JCL SAS and Easytreve.

But SAS was actually the very first programming language I learned, before the programmer trainee job even started. So when I got the opportunity to be a "real" programmer, one of my choices was to work in the Cobol side of the shop or the "ad-hoc" SAS side of the shop. I chose working on the SAS side of things and have been using SAS ever since.

So it's been a very, -very- long time that I have worked with SAS. I don't know "everything" about SAS -- but I do know how to look things up in the documentation. And, there's the whole puzzle aspect of solving a problem that I find appealing.

My students all speak highly of these authors: Cody, Carpenter, Delwiche/Slaughter, Burlew and Haworth. But there are many other good books available on different topics (For example, I don't teach Stat classes, so I don't know what Stat-related books are most useful.)

The best advice I can give you is learn how to use the resources on support.sas.com -- the search facility, the documentation, the samples and the repository of SAS Global Forum papers. And, don't be afraid to ask yourself "what if" questions and test out your theories or ideas in a test program on sample data.

Good luck!

cynthia

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-29-2009 10:40 AM

Thank you for the inputs and advices. I will definitly look into these resources. But I think I should read a few SAS books again just to get a better understanding on everything. I went through both the BASE and ADVANCED SAS certification exam and I feel at the end I remembered and learned nothing. I keep getting stuck on small problems. This just makes me sad. It is like spending so much time and effort and at end you got nothing from it. I have been a SAS programmer for a year and half now and I feel that my skills on SAS did not improve at all. Ok, i need to stop whining and start reading and check on these resources. Thanks again!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-29-2009 11:23 AM

My recommendation - stop reading and start coding!

Then, refer to the SAS documentation and SAS support website resources, as needed, or when you might want to review a particular PROC and/or DATA step programming element.

Scott Barry

SBBWorks, Inc.

Then, refer to the SAS documentation and SAS support website resources, as needed, or when you might want to review a particular PROC and/or DATA step programming element.

Scott Barry

SBBWorks, Inc.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-29-2009 03:06 PM

Yes. I think you are right. This is a good place to start. Where I can try to solve other people's questions which will give me practice and help memorize the functions.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-28-2009 01:36 PM

hehe, i thought that didn't work but that's because my output wasn't formatted. thanks.
Message was edited by: cosmid

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-29-2009 11:43 AM

i ran through this exercise a little while ago.

to import a YYYYMMDD-style integer into a sas date value, i use the ND8601DA. informat and apply the date9. format. YYYYMMDDHHMMSS-style integer into a sas datetime value, one can use the ND8601DT. informat and apply the datetime19. format.

http://quatch.koopmann.us/2009/05/reading-iso-dates-and-datetimes.html

to import a YYYYMMDD-style integer into a sas date value, i use the ND8601DA. informat and apply the date9. format. YYYYMMDDHHMMSS-style integer into a sas datetime value, one can use the ND8601DT. informat and apply the datetime19. format.

http://quatch.koopmann.us/2009/05/reading-iso-dates-and-datetimes.html

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-29-2009 03:06 PM

oh, thanks. never heard about this format. will read about it now.