BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yelena
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

 

View solution in original post

10 REPLIES 10
Reeza
Super User

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. 

yelena
Fluorite | Level 6

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?

yelena
Fluorite | Level 6

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?

Reeza
Super User

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?  

 

 

 

 

yelena
Fluorite | Level 6

I am trying but if I have a long format I cannot see the distinction of selected variable.

 

 

Reeza
Super User

Each variable would be its own chart? Isn't that what you want? 

 

Try it, post the code if your having issues. 

yelena
Fluorite | Level 6

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.

Reeza
Super User

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;

 

yelena
Fluorite | Level 6

Dear Reeza,

Thank you very much! This is exactly what I was trying to get. Thank you so much for your prompt help!

Yelena

yelena
Fluorite | Level 6

I have transformed the data as otherwise it does not work. Not I have a column "year" and "X1" - "X3"

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 10 replies
  • 1570 views
  • 0 likes
  • 2 in conversation