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 |
i have a dataset with var1,var2,var3; i want to upload the titles for the variables . How can we?
describe how to adjust the performance of data integrator? : Sas-di
How the Excel file enter into the SAS environment without Code of Infile & Import procs,if i have no file Conversion?
how we can call macros with in data step?
Will it bother you if the guy at the next desk times the frequency and duration of your bathroom or coffee breaks on the grounds that ?you are getting paid twice as much as he is??
what is Enterprise Guide?what is the use of it?
what is the use of proc contents and proc print in sas? : Sas-administrator
What is data _null_?
what are the sites did u refer for enquiries and doubts for SAS
DATA ABC; INPUT TDATE DATE9. AVG; CARDS; 18APR2008 150.00 19APR2008 167.00 20APR2008 123.00 21APR2008 145.00 ; RUN HOW CAN I FIND THE DIFFERENCE BETWEEN AVG OF 18APR2008 ANF 21APR2008?? IF ANY ONE GETS IT PLS TRY TO POST IT.
8 Answers Verinon Technology Solutions,
How would you code a macro statement to produce information on the sas log? This statement can be coded anywhere? : sas-macro
How to limit decimal places for variable using proc means?