Dear all,
I am trying to create a histogram (with kernel and mean and std. deviation measurements) for a number of variables over time. So that we have percent on y=axis and years on x-axis. Plus I need to make sure that in the title of each histogam I have the description of each variable. Does anyone know how to do it?
For example, the data should look like this:
Variable Description 2005 2006 2007
X1 Current Asset 1 0.07 0.01 0.90
X2 Current Asset 2 0.86 0.2 0.03
X3 Current Asset 3 0.45 0.4 0.5
Thank you
This should give you the idea. You can use a similar idea with proc univariate.
data have;
informat variable $2. description $25.;
input Variable $ Description $ Y2005 Y2006 Y2007;
cards;
X1 Current_Asset_1 0.07 0.01 0.90
X2 Current_Asset_2 0.86 0.2 0.03
X3 Current_Asset_3 0.45 0.4 0.5
;
run;
*transpose to long;
data long;
set have;
array years(2005:2007) y2005-y2007;
do Year=2005 to 2007;
Value=years(year);
output;
end;
drop y20:;
run;
*sort on description;
proc sort data=long;
by description year;
run;
*Graph using vbarparm;
proc sgplot data=long;
title1 '#byval1';
by Description;
vbarparm category=year response=value;
run;quit;
A histogram over time? A histogram usually only has one variable and shows the distribution of that variable. I'm not understanding how you want to incorporate time.
Hello, Reeza,
I guess they called it histograms but need two things; (1) the % coverage of one variable over time; (2) histograms per year of each variable (I am not sure how to do it though).
For (1) I tried to run the following program:
proc sgplot data=have;
series x = year y = X1;
xaxis values=(2005 to 2015);
run;
For (2) I tried to run the following program:
proc univariate data=have noprint;
class year;
histogram X1 / barlabel= percent kernel(c = 0.25 0.50 0.75 1.00
noprint);
run;
Also, since I have hundreds of variables, is there a way to send all those grpahs in excel directly?
proc sgplot data=sql.Compustat_Coverage;
series x = year y = X1;
xaxis values=(2005 to 2015);
run;
If I need to run over other variables, what would be the best way. &list?
That's not a histogram that's a scatter plot.
I would transpose my data to a long format and use BY processing. BY processing also allows for dynamic titles.
I think your going to need to do that anyways for it to work. Wouldn't the year need to be a column rather than a column for every year, which is what you have now?
I am trying but if I have a long format I cannot see the distinction of selected variable.
Each variable would be its own chart? Isn't that what you want?
Try it, post the code if your having issues.
I am trying this now:
data want;
length variable $32;
set have;
array var_list(*) &list;
do i = 1 to dim(var_list);
variable = vname(var_list{i});
value = var_list{i};
output;
end;
keep year variable value;
run;
proc univariate data=want noprint;
class year variable;
histogram value / barlabel= percent kernel;
run;
It is not working.
This should give you the idea. You can use a similar idea with proc univariate.
data have;
informat variable $2. description $25.;
input Variable $ Description $ Y2005 Y2006 Y2007;
cards;
X1 Current_Asset_1 0.07 0.01 0.90
X2 Current_Asset_2 0.86 0.2 0.03
X3 Current_Asset_3 0.45 0.4 0.5
;
run;
*transpose to long;
data long;
set have;
array years(2005:2007) y2005-y2007;
do Year=2005 to 2007;
Value=years(year);
output;
end;
drop y20:;
run;
*sort on description;
proc sort data=long;
by description year;
run;
*Graph using vbarparm;
proc sgplot data=long;
title1 '#byval1';
by Description;
vbarparm category=year response=value;
run;quit;
Dear Reeza,
Thank you very much! This is exactly what I was trying to get. Thank you so much for your prompt help!
Yelena
I have transformed the data as otherwise it does not work. Not I have a column "year" and "X1" - "X3"
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.