Desktop productivity for business analysts and programmers

PROC UNIVARIATE (Histogram) Formatting of Variables

Reply
Occasional Contributor
Posts: 14

PROC UNIVARIATE (Histogram) Formatting of Variables

Hi,

I'm using SAS EG and doing a Historgram using PROC UNIVARIATE (SAS EG 6.1 running SAS 9.2 TS2M3 on LINUX).  I'm suppressing the actual charts but putting the output variables to a table (mean, std, median, var, etc). Is there a way to format these output variables to something like 8.2 or the like in the actual PROC itself?  I could create another datastep to do this but I don't want to add another step. There's probably no way using the actual Distribution 'node' in EG, but maybe just using the SAS code for PROC UNIVARIATE?

 

Thanks,

Dave

Community Manager
Posts: 2,884

Re: PROC UNIVARIATE (Histogram) Formatting of Variables

You can modify the output template using PROC TEMPLATE.  @Bari_sas recently shared an example that might be really useful for you.

Occasional Contributor
Posts: 14

Re: PROC UNIVARIATE (Histogram) Formatting of Variables

Hi Chris,
I'll check this out. I'm very much a novice with PROC TEMPLATE. Been writing code for 23 years...never used PROC TEMPLATE. Smiley Sad
Thanks!
Occasional Contributor
Posts: 14

PROC UNIVARIATE (Histogram) Formatting of Variables

Hi,

I'm using SAS EG and doing a Historgram using PROC UNIVARIATE (SAS EG 6.1 running SAS 9.2 TS2M3 on LINUX).  I'm suppressing the actual charts but putting the output variables to a table (mean, std, median, var, etc). Is there a way to format these output variables to something like 8.2 or the like in the actual PROC itself?  I could create another datastep to do this but I don't want to add another step. There's probably no way using the actual Distribution 'node' in EG, but maybe just using the SAS code for PROC UNIVARIATE?

 

Thanks,

Dave

Super User
Posts: 19,034

Re: PROC UNIVARIATE (Histogram) Formatting of Variables

When you switch to SAS 9.3+ you can use STACKODS in proc means, but before that I think you're stuck with manipulating the data Smiley Sad

 

 

Occasional Contributor
Posts: 14

Re: PROC UNIVARIATE (Histogram) Formatting of Variables

Hi Reeza,
Ok, thanks!
Community Manager
Posts: 2,884

Re: PROC UNIVARIATE (Histogram) Formatting of Variables

Here's an example of STACKODSOUTPUT (scroll way down in the blog for explanation).  Code:

 

/* Use the STACKODSOUTPUT option on the PROC MEANS statement   */
/* and use the ODS OUTPUT statement to create output data set. */
 
ods output summary=with_stackods(drop=_control_);
proc means data=sashelp.class stackodsoutput sum mean std nway;
 class sex;
 var height weight;
run;
 
proc print data=with_stackods noobs;
 title 'Output data set with STACKODSOUTPUT';
run;
SAS Super FREQ
Posts: 3,618

Re: PROC UNIVARIATE (Histogram) Formatting of Variables

An alternative to STACKODS output is to use the OUTTABLE= option in PROC UNIVARIATE. This enables you to write all descritive statistics to a SAS data set with minimal effort.  It is eons old, so it is surely included in whatever version of SAS you are running. For an example, see the article "Save descriptive statistics for multiple variables in a SAS data set."

 

Remember, too, that you don't need to use a DATA step to change the format for some variable.  You can use the FORMAT statement in any SAS procedure to temprarily assign a format to a variable for the duration of that procedure. For example:

proc print data=have;

format x y z 8.2;

var x y z;

run;

 

Occasional Contributor
Posts: 14

Re: PROC UNIVARIATE (Histogram) Formatting of Variables

Excellent...thanks!
PROC Star
Posts: 1,143

Re: PROC UNIVARIATE (Histogram) Formatting of Variables

If you do end up using PROC TEMPLATE, I was in the same position as you about 6 months ago. The SAS documentation isn't bad, but I found what really helped was googling whatever the particular thing I was trying to do. There's a huge number of absolutely fantastic SGF papers that solved (almost) every problem I had.

 

Tom

Occasional Contributor
Posts: 14

Re: PROC UNIVARIATE (Histogram) Formatting of Variables

Hi Tom,
That EXCELLENT...and good to know. I need to start familiarizing myself with that stuff Smiley Happy
Super User
Posts: 19,034

Re: PROC UNIVARIATE (Histogram) Formatting of Variables

To add to Tom's great suggestion, search on lexjansen.com to limit your search to SAS papers.

Ask a Question
Discussion stats
  • 11 replies
  • 856 views
  • 2 likes
  • 5 in conversation