Hi there, I want to plot a earnings release date distribution based on Fama French Industry 12 as follows.
However, I can only get the graph as follows.
My code is like:
ods graphics / antialias=on antialiasmax=22400 width=600px height=500px;
proc sgplot data=dist.dist_2017;
symbolchar name=line char='2509'x;
scatter x=ind_code y=datadate/markerattrs=(symbol=line size=7pt);
xaxis values=(1 2 3 4 5 6 7 8 9 10 11 12) label='Industry';
yaxis interval=day label='Release Date';
title "Distribution of Earnings Release Date";
run;
I have spent hours working on it. Could anyone help me figure it out?
Thank you so much!
Can you post some sample data?
SAS dates are stored as numbers (days since Jan 1, 1960) and your numbers span more than 1 year, so you are getting two years of dates. It sounds like you want to plot the release dates as "Day of the Yera", which is the number of days since 01JAN of the year that the data was released. To do that, you can use the DAY and MONTH functions to extract the day and month, and then pretend that all dates are in the same year. This method isn't perfect because of leap years, but it is close, and the years 2017 and 2018 were not leap years.)
data dist_2017; /* make up fake data */
format datadate DATE10.;
min = '20JUN2017'd;
max = '30MAY2018'd;
do ind_code = 1 to 12;
do k = 1 to 20;
datadate = rand('uniform', min, max);
output;
end;
end;
drop min max k;
run;
data DayMonth;
set dist_2017;
Day = day(datadate);
Month = month(datadate);
DayOfYear = mdy(Month, Day, 2017) - '31DEC2016'd; /* compute day of the year */
run;
proc sgplot data=DayMonth;
symbolchar name=line char='2509'x;
scatter x=ind_code y=DayOfYear / markerattrs=(symbol=line size=7pt);
xaxis type=discrete label='Industry';
yaxis label='Release Date (Day of Year)';
title "Distribution of Earnings Release Date";
run;
The YAXIS statement supports the TICKVALUEFORMAT= option that allows you specify a different format to display the tickmarks, please note that all the NL... formats will react to the LOCALE= setting on how to display a date. You can also use the VALUES= option to specify your tickmark values. See the examples below.
To get longer "symbols" you can use the TEXT plot statement.
Here are some examples (data comes from the sample provide by @Rick_SAS :
data DayMonth;
set dist_2017;
Day = day(datadate);
Month = month(datadate);
DayOfYear = mdy(Month, Day, 2017) - '31DEC2016'd; /* compute day of the year */
text = "——";
run;
options locale=en_us;
proc sgplot data=DayMonth;
symbolchar name=line char='2509'x;
scatter x=ind_code y=datadate / markerattrs=(symbol=line size=7pt);
xaxis type=discrete label='Industry';
yaxis label='Release Date (Day of Year)' type=time interval=quarter TICKVALUEFORMAT=nldatemdm6.;
title "Distribution of Earnings Release Date";
format datadate date9.;
run;
proc sgplot data=DayMonth;
symbolchar name=line char='2509'x;
scatter x=ind_code y=datadate / markerattrs=(symbol=line size=7pt);
text x=ind_code y=datadate text=text / textattrs=(color=red);
xaxis type=discrete label='Industry';
yaxis label='Release Date (Day of Year)' type=time
values=("20jul2017"d "08sep2017"d "28oct2017"d "17dec2017"d "05feb2018"d "27mar2018"d "16may2018"d "05jul2018"d)
tickvalueformat=nldatemdm6.
;
title "Distribution of Earnings Release Date";
format datadate date9.;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.