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 |
Why is SAS considered self-documenting?
I need level 2 to 5 sas using companies in india
What is the pound sign used for in the data_null_ ?
You need to create an In List that it is to be later used in a Where Clause that includes all the Regions that begin with the letter A from the sashelp.shoes table. Using PROC SQL with an into clause create the following string from the sashelp.shoes table using the variable region “AFRICA”,”ASIA”,…..
Have you ever linked SAS code, If so, describe the link and any required statements used to either process the code or the step itself?
what is the difference between proc means and proc tabulate?
IS SAS COMPILER OR INTERPRETER? EXPLAIN?
3 Answers Aon Hewitt, HSBC, SCL, TCS,
What would you change about your job?
How do you connect the desktop application to metadata server? : sas-grid-administration
how can u convert this 25-jul-2010 from numeric to charcter?
Of all your work, where have you been the most successful?
How would you delete observations with duplicate keys?