BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
annapurna
Calcite | Level 5

There is a field containing a date. It needs to be displayed in the format “ddmonyy” if it’s before 1975, “dd mon ccyy” if it’s after 1985, and as ‘Disco Years’ if it’s between 1975 and 1985.

I have used the following code

data new ;

input date ddmmyy10. ;

cards;

01/05/1955

01/09/1970

01/12/1975

19/10/1979

25/10/1982

10/10/1988

27/12/1991

;

run;

proc format ;

value dat low-’01jan1975’d=ddmmyy10.

’01jan1975’d-’01JAN1985’d=”Disco Years”

’01JAN1985’d-high=date9.;

run;

proc print;

format date dat. ;

run;

but am not getting the expected result

can anyone help me.

1 ACCEPTED SOLUTION

Accepted Solutions
bharathtuppad
Obsidian | Level 7

Proc format ;

Value test low-"31dec1974"d =[date7.]

               "01jan1975"d - "31dec1985"d = "disco years"

              "01jan1986"disco - high =[ddmmyy10.];

Run;

Use this format test.

View solution in original post

8 REPLIES 8
bharathtuppad
Obsidian | Level 7

Proc format ;

Value test low-"31dec1974"d =[date7.]

               "01jan1975"d - "31dec1985"d = "disco years"

              "01jan1986"disco - high =[ddmmyy10.];

Run;

Use this format test.

Reeza
Super User

Lsat one should be date9? And no disco in the range Smiley Happy

bharathtuppad
Obsidian | Level 7

Yes, typo error, my mistake. It is d in the range not disco.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Personally I am not a fan of formats, so I would just do a case statement (or if) into a character field:

proc sql;

     create table WANT as

     select     DATE,

                    case     when DATE <= '01JAN1975'd then put(date,ddmmyy10.)

                                 when '01JAN1975'd < DATE <= '01JAN1985'd then "Disco Years"

                                 else put(DATE,date9.) end as PROCESSED_DATE

     from        HAVE;

quit;

annapurna
Calcite | Level 5

thankyou guys for helping me

annapurna
Calcite | Level 5

in response to Rw9,

that code was working good

but if i try the same approach in a data step with select when statement it s not working

why doesnt it work .

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Perhaps pop your code in your post, then I could see.  This should work:

data want;

  set new;

  length processed_date $200.;

  select;

    when (date <= '01JAN1975'd) processed_date=put(date,ddmmyy10.);

    when ('01JAN1975'd < date < '01JAN1985'd) processed_date="Disco";

    otherwise processed_date=put(date,date9.);

  end;

run;

annapurna
Calcite | Level 5

i wrote the code wrong

i mentioned the variable name in select statement as well

rest all i hav written the same

thankyou so much Rw9

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 8 replies
  • 1533 views
  • 11 likes
  • 4 in conversation