BookmarkSubscribeRSS Feed
huangmuzuohe
Calcite | Level 5

Hi there, I want to plot a earnings release date distribution based on Fama French Industry 12 as follows. 1.jpg

However, I can only get the graph as follows.

2.jpg

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!

 

 

 

 

3 REPLIES 3
Rick_SAS
SAS Super FREQ

Can you post some sample data?

Rick_SAS
SAS Super FREQ

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;
BrunoMueller
SAS Super FREQ

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 317 views
  • 0 likes
  • 3 in conversation