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.
Proc format ;
Value test low-"31dec1974"d =[date7.]
"01jan1975"d - "31dec1985"d = "disco years"
"01jan1986"disco - high =[ddmmyy10.];
Run;
Use this format test.
Proc format ;
Value test low-"31dec1974"d =[date7.]
"01jan1975"d - "31dec1985"d = "disco years"
"01jan1986"disco - high =[ddmmyy10.];
Run;
Use this format test.
Lsat one should be date9? And no disco in the range
Yes, typo error, my mistake. It is d in the range not disco.
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;
thankyou guys for helping me
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 .
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;
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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.