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



There is a field containing a date. It needs to be displayed in the format "ddmonyy" i..

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

There is a field containing a date. It needs to be displayed in the format "ddmonyy" i..

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

There is a field containing a date. It needs to be displayed in the format "ddmonyy" i..

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

There is a field containing a date. It needs to be displayed in the format "ddmonyy" i..

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

There is a field containing a date. It needs to be displayed in the format "ddmonyy" i..

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

There is a field containing a date. It needs to be displayed in the format "ddmonyy" i..

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

There is a field containing a date. It needs to be displayed in the format "ddmonyy" i..

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

There is a field containing a date. It needs to be displayed in the format "ddmonyy" i..

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

Post New Answer

More SAS Interview Questions

What is the length assigned to the target variable by the scan function?

0 Answers  


I have a SCD Type 2 Dimention for Location In which A Sales Office in Having two Surrogate Keys just because of the change in it's Sales Group. SKey SalesGroup Sales Office BeginDate EndDate 280 SG1 SO1 01APR2000 01APR2010 281 SG2 SO1 02APR2010 31MAR2999 Now while loading the Fact, the Lookup ir returning SKey 280 for records before and after 01APR2010. I am not able to give WHERE condition in the Lookup Properties (TranDate between BeginDate and EndDate). Please help.

0 Answers  


why is the use of Retrive statement and give me with example?

1 Answers   ME,


What is the order of evaluation of the comparison && logical && relational operators:?

2 Answers   CitiGroup,


6) Explain about below automatic variables a) _N_ b) _ERROR_ c) _CHAR_ d) _NUMERIC_ e) _ALL_ f) FIRST.BY VARIABLE g) LAST.BY VARIABLE h) _NAME_ i) _TYPE_ j) _FREQ_ k) _STAT_ l) _BREAK

1 Answers   IBM, SAS,






where will go the observations that were deleted by delete statement?

2 Answers  


what are methods to identify duplicate observations?

5 Answers   HCL,


What are the functions which are used for character handling functions?

0 Answers  


What is the one statement to set the criteria of data that can be coded in any step?

4 Answers   Accenture,


how many types of prompts are there? : Sas-bi

0 Answers  


% let A=3+4 what is result

4 Answers   Satyam,


How to convert a given date value into SAS date

9 Answers   CitiGroup, Quintiles,


Categories