DATA Step, Macro, Functions and more

DATE VALUES

Reply
Contributor sss
Contributor
Posts: 65

DATE VALUES

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

PROC Star
Posts: 7,468

DATE VALUES

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;

Contributor sss
Contributor
Posts: 65

DATE VALUES

but now the date variable is in best12. format

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

PROC Star
Posts: 7,468

DATE VALUES

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?

Contributor sss
Contributor
Posts: 65

DATE VALUES

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

PROC Star
Posts: 7,468

Re: DATE VALUES

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.

Super User
Super User
Posts: 7,039

Re: DATE VALUES

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;

Contributor sss
Contributor
Posts: 65

DATE VALUES

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

PROC Star
Posts: 7,468

DATE VALUES

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;

Contributor sss
Contributor
Posts: 65

DATE VALUES

thnx u vry much

Ask a Question
Discussion stats
  • 9 replies
  • 293 views
  • 3 likes
  • 3 in conversation