The SAS Output Delivery System and reporting techniques

Proc Report Date Format

Accepted Solution Solved
Reply
SAS Employee
Posts: 73
Accepted Solution

Proc Report Date Format

I have date in proc report as : 20110812 but i would like to format it as 08-12-2011

What format do i need to use ?


Accepted Solutions
Solution
‎08-12-2011 02:24 PM
PROC Star
Posts: 7,492

Re: Proc Report Date Format

I'm not well versed in proc report but, that said, the following works for me:

data have;

  input name $ havedate;

  cards;

John 20110811

Mary 20110812

;

options datestyle=ymd;

PROC REPORT NOWD DATA=have HEADLINE HEADSKIP CENTER MISSING;

  COLUMNS NAME havedate date;

  define havedate/display noprint;

  define date/computed format=yymmddd10.;

  COMPUTE date;

    date=input(put(havedate,z8.),anydtdte.);

  ENDCOMP;

RUN;

View solution in original post


All Replies
Contributor
Posts: 66

Proc Report Date Format

try mmddyy10.

SAS Employee
Posts: 73

Proc Report Date Format

Posted in reply to asishgautam

mmddyy10. did not work.

New Contributor lho
New Contributor
Posts: 3

Proc Report Date Format

I have the exact same question! Need to change 20110812 to be 08/12/2011. It's quite frustrating. I tried format mmddyy10. and format yymmdd10. Neither worked.

PROC Star
Posts: 7,492

Proc Report Date Format

If the "date" is actually a character field, then you have to create a numeric field.  In a datastep, that could be accomplished with:

data have;

  input date $;

  format wantdate mmddyyd10.;

  wantdate=input(date,yymmdd8.);

  cards;

20110812

;

To get a slash, rather than a hyphen, just change the d10 in the format to s10.

New Contributor lho
New Contributor
Posts: 3

Proc Report Date Format

Mine is not character, it is in numeric format.

SAS Employee
Posts: 73

Re: Proc Report Date Format

Mine is numeric as well

PROC Star
Posts: 7,492

Re: Proc Report Date Format

If it is the number 20110812, what happens if you try:

options datestyle=ymd;

data have;

  input date;

  format date mmddyyd10.;

  date=input(put(date,z8.),anydtdte.);

  cards;

20110812

;

SAS Employee
Posts: 73

Re: Proc Report Date Format

This gives me sas date - 18850

PROC Star
Posts: 7,492

Re: Proc Report Date Format

That is one number off but, if you apply the format, you should get what you want.  I ran:

options datestyle=ymd;

data have;

  input date;

  format date mmddyyd10.;

  date=input(put(date,z8.),anydtdte.);

  cards;

20110812

;

proc print;run;

and got:

Obs          date

  1     08-12-2011

SAS Employee
Posts: 73

Re: Proc Report Date Format

Art,

You code work but for some reason when i apply it to my code it doesn't work.  Here is my code.  Am i missing anything ?

Options datastyle=ymd;

ods html file = 'path'

Proc Report ......

Column  Date / Format=mmddyy10. group 'date' missing noprint;

compute before Date / Style=[just=l];

text1 = 'Date = ' || trim(left(input(put(date,z8.),anydtdte.)));

.....

Solution
‎08-12-2011 02:24 PM
PROC Star
Posts: 7,492

Re: Proc Report Date Format

I'm not well versed in proc report but, that said, the following works for me:

data have;

  input name $ havedate;

  cards;

John 20110811

Mary 20110812

;

options datestyle=ymd;

PROC REPORT NOWD DATA=have HEADLINE HEADSKIP CENTER MISSING;

  COLUMNS NAME havedate date;

  define havedate/display noprint;

  define date/computed format=yymmddd10.;

  COMPUTE date;

    date=input(put(havedate,z8.),anydtdte.);

  ENDCOMP;

RUN;

SAS Employee
Posts: 73

Re: Proc Report Date Format

Thanks.  It did work fo rme. 

Contributor
Posts: 24

Re: Proc Report Date Format

it should be works;

data test;

input d $;

format dt mmddyyd10. st mmddyys10.;

dt=input(d,yymmdd8.);

st=dt;

cards;

20110812

;

run;

proc report nowd;

column d dt st;

define d/display;

define dt/display;

define st/display;

quit;

Contributor
Posts: 66

Proc Report Date Format

i had this wrong:

try the following:

data test ;

    informat dval yymmdd8. ;

    format dval yymmdd10. ;

    input @1 dval  ;

    datalines ;

    20110812

    20110813

    20110814

    20110815

    20110816

    20110817

    ;

run ;

🔒 This topic is solved and locked.

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

Discussion stats
  • 16 replies
  • 2852 views
  • 0 likes
  • 5 in conversation