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.
How would you accomplish this in data step code? Using
only PROC FORMAT
Answers were Sorted based on User's Feedback
Answer / sudheendra reddy & veerend
DATA D1;
INPUT SLNO DATE DATE7.;
DATALINES;
1 12DEC73
2 22NOV71
3 01JAN76
4 12FEB77
5 13MAR83
6 24APR90
7 17MAY99
;
RUN;
proc format ;
value dat low-'31DEC1974'd=[date7.]
'01JAN1975'd-'31DEC1984'd="Disco Years"
'01JAN1985'd-high=[date9.];
RUN;
proc print data=D1 noobs label;
format DATE dat.;
RUN;
Is This Answer Correct ? | 7 Yes | 0 No |
Answer / paul
proc format ;
value dat low-'31DEC1974'd=[date7.]
'01JAN1975'd-'31DEC1985'd="Disco Years"
'01JAN1986'd-high=[date9.];
run;
proc sql;
select date format=dat. from D1 ;
quit;
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / amit gupta
Apologies,
above code has an extra "FROM d1"
The working code is as below:
proc sql;
select
case when date lt '31DEC2006'd then date end as mydate
format=date7. ,
case when date gt '31DEC2008'd then date end as mydate
format=date9. ,
case when '01JAN2007'd <= date <= '31DEC2008'd then 'DUMMY'
end as mydate
from d1 ;
quit;
However it does give the data in 3 columns , which I was
unable to merge as the data type was different.
Any working solution using format ?
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / amit gupta
proc sql;
select
case when date lt '31DEC2006'd then date end as mydate
format=date7. from d1
case when date gt '31DEC2008'd then date end as mydate
format=date9. ,
case when '01JAN2007'd <= date <= '31DEC2008'd then 'DUMMY'
end as mydate
from d1 ;
quit;
Just that these are in three different columns;
Tried the above resolutions but unsuccessfully.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / schuler
data formated(keep=datenew);
length datenew $10.;
set new;
if date<'31dec1974'd then datenew=put(date,date7.);
else if date>'31dec1984'd then datenew=put(date,date7.);
else datenew='Disco Year';
run;
proc print data=formated nobs;run;
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sheldon
proc sql;
create table fmtdate(keep=newdate) as
select date,
case
when date lt '31DEC1974'd then put(date,date7.)
when date gt '31DEC1984'd then put(date,date9.)
else 'Desco Year'
end as newdate
from d1;
quit;
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / vijs
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;
run;
proc print;
format date dat. ;
run;
Is This Answer Correct ? | 3 Yes | 5 No |
Answer / kavitha
DATA D1;
INPUT SLNO DATE DATE9. ;
DATALINES;
1 12DEC08
2 22NOV08
3 01JAN08
4 12FEB07
5 13MAR07
6 24APR06
7 17MAY06
8 20JUN05
9 29JUL05
10 30APR09
;
RUN;
proc format ;
value KAVI low-'31DEC2006'd='***ddmonyy***'
'01JAN2007'd-'31DEC2007'd='***dd mon ccyy***'
'01JAN2008'd-high=' **Disco Years **';
RUN;
proc print data=D2 noobs label;
format DATE KAVI.;
RUN;
Is This Answer Correct ? | 2 Yes | 5 No |
Explain append procedure?
WHAT DIFFERRENCE DID YOU FIND AMONG VERSION 6 8 AND 9 OF SAS.
why is a stop statement needed for the point=option on a set statement? : Sas programming
how does sas handle missing values in assignment statements? : Sas programming
what cause the "error: connect:" and "error in the libname statement" when there weren't any such problems?
What happens in the following code, if u type 8 instead of *? proc sql noprint; create table abc as select 8 from lib.abc; quit;
Can anyone help to find a statement to get all the predefined formats?
3 Answers Verinon Technology Solutions,
How would you identify a macro variable?
Approximately what date is represented by SAS date value of 730
I have 2 data sets A & B. Both have a variable called Age in them, each of them specifying a different functionality. In my program I use bot these data sets. How do I specify which Age variable I want to use?
How sas treats the dsd delimiters?
Differentiate between ceil and floor functions.