Contributor
Posts: 25

Macro to generate distribution of character variables

Hi,

Does any one have a macro to generate distribution plots for character variables in a dataset. The distribution should contain N, NMISS for each variable and for each time period. The plot should have date on x-axis and percentage on Y-axis (NMISS percentage for example). I  have 269 char variables and I've to plot their distribution. Any help or suggestion  would be appreciated.

RK

Super User
Posts: 23,714

Re: Macro to generate distribution of character variables

I have something that goes through and creates a table with the amount missing and percentages. You could then use that to plot I suppose.

Hopefully gets you started

Contributor
Posts: 25

Re: Macro to generate distribution of character variables

Reeza,

Thank you for your response. I need to plot more than missing and non missing distribution. I need to plot missing, and frequency of each value in a variable as stacked plot against time. Cumulative distributive percent is the Y-axis and time is X-axis. Could you or anyone suggest me how to proceed?

Thanks,

RK

Super User
Posts: 23,714

Re: Macro to generate distribution of character variables

1. Create a format that creates your non-missing/missing variables

See here how to do the format.

http://www2.sas.com/proceedings/sugi30/001-30.pdf

2. Run a proc freq with your character variables against your time variable, applying the format to your 269 variables. You can use the _character_ key word if possible.

3. Plot the results from #2.

Add a step in between 2 and 3, a datastep that calculates the cumulative total over the time.

Contributor
Posts: 25

Re: Macro to generate distribution of character variables

Reeza,

Thanks for your response. I am trying to generate a stacked band plot with my data. but I coudln't generate it. I want evt_dt on x-axis and stacked graph with Y,N, and missing values percentage distribution filled with different colour. Could anyone identify the problem? Following is the code:

proc sgplot data=t2 cycleattrs ;

band x=evt_dt upper= mode_rate lower=0 /  group=char_var  name="vars" fill ;

yaxis min=0  label="CUM DIST PCT" grid;

xaxis label="evt_dt" Type=Discrete FitPolicy=RotateThin;

series x=evt_dt y=pct_row / lineattrs=(pattern=solid thickness=1.5px) markerattrs=(symbol=circlefilled)

markers group=char_var name="vars";

keylegend "vars" / location=outside position = right VALUEATTRS=(SIZE=10);

run;

data looks like following:

evt_dt,char_var,pct_row,cum_pct

02sep2011,missing,25,25%

02sep2011,N,25,50%

02sep2011,Y,50,100%

---------------

------------

i have referred following sample but couldn't generate the plot:

http://support.sas.com/kb/31/510.html