DATA Step, Macro, Functions and more

Generate Table Using Proc Format and ?

Reply
Regular Learner
Posts: 1

Generate Table Using Proc Format and ?

[ Edited ]

Trying to produce a table that is exactly as shown. Can this been done with Proc Format and only one other procedure? Or do I need to setup the dataset to get the look at want when using something like proc tabulate?

 

Characteristic is the variables names and the Group is the variable values. (N is the counts and % is the percent of Characteristic)

 

 

Update: Proc Format is taken care of. The second image is what I got so far. I need the varable names in a seperate column to the left just like the from the first image.


Untitled.jpgUntitled2.jpg
Super User
Posts: 5,427

Re: Generate Table Using Proc Format and ?

Posted in reply to DATA_ALAN
What will be the values?
Spontaneously I see three separate tables, probably generated by PROC TABULATE.
One way to solve this is to store the output of each tabulate in common data set, and then PROC PRINT that.
Data never sleeps
Trusted Advisor
Posts: 1,560

Re: Generate Table Using Proc Format and ?

Posted in reply to DATA_ALAN

It seems to me that you need 3 different formats:

   (1) for gender, (2) for age group, (3) for employment

 

Usually a format usage is to convert or display a text instead of a code,

but I don't see codes in your table.

 

Anyway, you may try use or addapt next proc format:

 

proc format lib=work;  /* you can use another library */

      value $gender      /* $ for chracter format */

          'F' = 'Female'

          'M' = 'Male'

       ;

     value age_dec

          2 = '20s'

          3 = '30s'

          ...

          6 = '60+'

       other = '??'    /* undefined */

     ;

     value $employ

        'Full' = 'Full Time'

        'Part' = 'Part Time'

      ;

   run;

 

Having the formats, you can use Proc Tabulate (or other procedures, depending on your dataset)

to displaty the data in the format you show. For more help - attach an example of your data or dataset.

 

 

Super User
Posts: 19,789

Re: Generate Table Using Proc Format and ?

Posted in reply to DATA_ALAN

You can do it solely with Proc Tabulate and formats. This is the easier method.

 

Proc Freq is another option as well with a bit of manipulation. You would add the formats for the variables into the proc freq.

 

*Run frequency for tables;
ods table onewayfreqs=temp;
proc freq data=sashelp.class;
	table sex age;
run;

*Format output;
data want;
length variable $32. variable_value $50.;
set temp;
Variable=scan(table, 2);

Variable_Value=strip(trim(vvaluex(variable)));

keep variable variable_value frequency percent cum:;
label variable='Variable' 
	variable_value='Variable Value';
run;

*Display;
proc print data=want(obs=20) label;
run;
Sign up for free

 

Ask a Question
Discussion stats
  • 3 replies
  • 215 views
  • 1 like
  • 4 in conversation