There might be a couple of different ways to do this. One way would be to create a format for it. The problem is that you will have to create four ranges for each year, this is not that hard, but you need to know the year ranges so to speak. So, basically you have a macro that takes start year and end year, creates all the rows needed in a table and then do a proc format with cntlin that points to the table you just created. Good thing with this is that you have no need for extra columns in your data. %macro createFormat(startYear,endYear);
data _format;
length label $ 20;
fmtname = "seasons";
%do _i=&startYear %to &endYear;
%do _month = 1 %to 12;
start = mdy(&_month,1,&_i);
end=intnx("month",start,0,"E");;
month = month(start);
if month in (1, 2, 12) then label="Summer";
else if month in (3, 4, 5) then label="Autumn";
else if month in (6, 7, 8) then label="Winter";
else if month in (9, 10, 11) then label="Spring";
output;
%end;
%end;
HLO = "O";
start = .;
end = .;
label = "Unknown";
output;
keep fmtname start end label;
run;
proc format cntlin=_format;
run;
%mend createFormat;
%createFormat(2000,2020);
data want;
input mydate date9.;
format mydate seasons.;
datalines;
15dec2017
15mar2017
15Jun2017
15Sep2017
.
;;;
run; The second way would be to create a new column with the month number in it and then create a format that just look at the month number and reformat this. But, you have to add a column to all the tables that you want to have this season variable. You can also use proc fcomp to create a function that is used to evaluate the date for you. proc fcmp outlib= work.funcs.season;
function whatseason (date) $ 15;
length return $ 15;
/*code*/
if month(date) in (1, 2, 12) then return="Summer";
else if month(date) in (3, 4, 5) then return="Autumn";
else if month(date) in (6, 7, 8) then return="Winter";
else if month(date) in (9, 10, 11) then return="Spring";
else return="????";
return(return);
endsub;
run;
options cmplib=work.funcs;
proc format;
value season (default=20) other = [whatseason()];
run;
data want;
input mydate date9.;
format mydate season.;
datalines;
15dec2017
15mar2017
15Jun2017
15Sep2017
.
;;;
run;
... View more