DATA Step, Macro, Functions and more

plot row pct by variable in a histogram

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 78
Accepted Solution

plot row pct by variable in a histogram

Is there any way to plot one variable and the row pct for that variable by another (from proq freq) as histogram?

 

Specifically, I have 2 variables, one is continuous that I am treating categorically (1-20) and the other is a binary 0/1 variable. I want to plot the first variable on the x axis and the row percent for the category 1 as the y axis.


Accepted Solutions
Solution
a month ago
Super User
Posts: 11,343

Re: plot row pct by variable in a histogram

What kind of plot? Scatter, bar, pie, line something else?

 

It may help to remember that the mean of 0/1 coded variable is the percent of 1 values. So with SGPLOT and Hbar or Vbar you could indicate the binary variable as the response variable and request the Stat=mean.

If you must see % symbols then assign a percent format to the binary variable for the plot. No need to use Proc Freq.

 

Other plots likely will require you to summarize the data, (hint: Proc means or Summary with your category variable as Class and the binary as a Var variable).

 

View solution in original post


All Replies
Solution
a month ago
Super User
Posts: 11,343

Re: plot row pct by variable in a histogram

What kind of plot? Scatter, bar, pie, line something else?

 

It may help to remember that the mean of 0/1 coded variable is the percent of 1 values. So with SGPLOT and Hbar or Vbar you could indicate the binary variable as the response variable and request the Stat=mean.

If you must see % symbols then assign a percent format to the binary variable for the plot. No need to use Proc Freq.

 

Other plots likely will require you to summarize the data, (hint: Proc means or Summary with your category variable as Class and the binary as a Var variable).

 

Frequent Contributor
Posts: 78

Re: plot row pct by variable in a histogram

worked beautifully - thank you.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 121 views
  • 1 like
  • 2 in conversation