Help using Base SAS procedures

proc format

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

proc format

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.


Accepted Solutions
Solution
‎12-15-2014 02:27 AM
Contributor
Posts: 27

Re: proc format

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


All Replies
Solution
‎12-15-2014 02:27 AM
Contributor
Posts: 27

Re: proc format

Proc format ;

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

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

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

Run;

Use this format test.

Super User
Posts: 17,840

Re: proc format

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

Contributor
Posts: 27

Re: proc format

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

Super User
Super User
Posts: 7,404

Re: proc format

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;

Occasional Contributor
Posts: 7

Re: proc format

thankyou guys for helping me

Occasional Contributor
Posts: 7

Re: proc format

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 .

Super User
Super User
Posts: 7,404

Re: proc format

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;

Occasional Contributor
Posts: 7

Re: proc format

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

☑ This topic is SOLVED.

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

Discussion stats
  • 8 replies
  • 424 views
  • 11 likes
  • 4 in conversation