BookmarkSubscribeRSS Feed
sss
Fluorite | Level 6 sss
Fluorite | Level 6

THIS IS THE SAMPLE CODE

DATA D;

INPUT DATE :BEST12.;

DATALINES;

20020328

19990214

;

RUN;

I WANT TO CONVERT DATE VARIABLE VALUES IN TO DATE9. FORMAT

PLEASE HELP ME OUT

9 REPLIES 9
art297
Opal | Level 21

I posted a response to your original thread:

I think that you are looking for something like:

data dunning;

  input DT_DUNNING_DATE;

  cards;

19980428

20100324

20110330

;

DATA TEMP;

  SET DUNNING;

  DT_DUNNING_DATE1=

   INPUT(put(DT_DUNNING_DATE,8.),yymmdd8.);

  FORMAT DT_DUNNING_DATE1 DATE9.;

RUN;

sss
Fluorite | Level 6 sss
Fluorite | Level 6

but now the date variable is in best12. format

i am not getting the way to convert it into date9. format.

art297
Opal | Level 21

Now it is a SAS date value with a date9. format.  That is what you will need if you want to use it as a date.

Do you not want it to be a SAS date but, rather, the text that only appears to look like a SAS date9. formated value?

sss
Fluorite | Level 6 sss
Fluorite | Level 6

ultimately what i want  is to convert those values in numbers of days so that i can apply date formats on it.

art297
Opal | Level 21

A SAS date value is simply a number representing the number of days since 01JAN1960.  As such, the difference between two SAS dates is the number of days that separate them.

Additionally, as Tom mentioned, you can do a lot more with the various date related functions.

Tom
Super User Tom
Super User

If you are reading the values from datalines or a text file then use the appropriate date format and the value will be stored as the number of days since 1/1/1960.  Then you can do differences and other operations on the date.  Look at functions that SAS has for date calculations for doing more complex operations with dates.

DATA D;

INPUT DATE yymmdd8.;

format date date9.;

CARDS;

20020328

19990214

RUN;

sss
Fluorite | Level 6 sss
Fluorite | Level 6

really thank full for your response

the main problem is that the dataset is alreadly created the date variable with best12. format.

i want to apply mmddyy or date9. format on it.. how can i pls guide me

art297
Opal | Level 21

I apparently don't understand what you are asking.  I had thought that what I suggested, before, matched your current situation.  I expanded on it, below, to show an example calculation:

data dunning;

  input DT_DUNNING_DATE;

  cards;

19980428

20100324

20110330

;

DATA TEMP;

  SET DUNNING;

  DT_DUNNING_DATE1=

   INPUT(put(DT_DUNNING_DATE,8.),yymmdd8.);

  FORMAT DT_DUNNING_DATE1 DATE9.;

  Number_of_Days_from_01JAN2010=

    DT_DUNNING_DATE1-'01JAN2010'd;

RUN;

sss
Fluorite | Level 6 sss
Fluorite | Level 6

thnx u vry much

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 9 replies
  • 1861 views
  • 3 likes
  • 3 in conversation