BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
newbi
SAS Employee

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

16 REPLIES 16
asishgautam
Calcite | Level 5

try mmddyy10.

newbi
SAS Employee

mmddyy10. did not work.

lho
Calcite | Level 5 lho
Calcite | Level 5

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.

art297
Opal | Level 21

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.

lho
Calcite | Level 5 lho
Calcite | Level 5

Mine is not character, it is in numeric format.

newbi
SAS Employee

Mine is numeric as well

art297
Opal | Level 21

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

;

newbi
SAS Employee

This gives me sas date - 18850

art297
Opal | Level 21

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

newbi
SAS Employee

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.)));

.....

art297
Opal | Level 21

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;

newbi
SAS Employee

Thanks.  It did work fo rme. 

SUN59338
Obsidian | Level 7

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;

asishgautam
Calcite | Level 5

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 ;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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