Help using Base SAS procedures

proc means with class YEAR and more variables, how to make individual tables for each variable?

Reply
Contributor
Posts: 30

proc means with class YEAR and more variables, how to make individual tables for each variable?

Hello everybody. I have a problem.

I have a dataset with some variables including the variable YEAR. I want to make some descr. statistics on the other variables for each year.

I use proc means with class YEAR and it works fine but there is a problem. I want to have descr. statistics on all the relevant variables in one PDF but with tables showing the statistics for each variable - so one table for each variable.

I have tried this (see below) but it just makes one table with both variables.

proc means data=XXXXX;

     class YEAR ;

     var AGE EXPERIENCE ;

run;

Do somebody know how to make this with indivudal tables for each variable??

Thank you! Smiley Happy

Best // Silas, Aarhus University, Institute of Economics

Super User
Super User
Posts: 6,499

Re: proc means with class YEAR and more variables, how to make individual tables for each variable?

Do you just want to run two proc means?

proc means data=xxxx;

  class year;

  var age ;

run;

proc means data=xxxx;

class year;

var experience;

run;

If more than a hand full then you could do it with a macro.

Contributor
Posts: 30

Re: proc means with class YEAR and more variables, how to make individual tables for each variable?

I am also ended with that solution now but since there are many variables and very big data set it is a very demanding procedure.

I wondered if there was a solution like when you work with proc freq you can have more variables in one print by this simple code.

proc freq data=XXXX;

tables YEAR*(AGE EXPERIENCE);

run;

And thanks!

Super User
Super User
Posts: 6,499

Re: proc means with class YEAR and more variables, how to make individual tables for each variable?

Why not just have PROC MEANS output a dataset and the use PRINT or REPORT to display it the way you want?

Contributor
Posts: 66

Re: proc means with class YEAR and more variables, how to make individual tables for each variable?

Have you looked into "by group" processing?  Note that this will require sorting your data set by the "by groups".

proc means data=XXXXX;

     by YEAR ;

     var AGE EXPERIENCE ;

run;

Super User
Posts: 10,497

Re: proc means with class YEAR and more variables, how to make individual tables for each variable?

One approach is to reshape your data.

data want (keep year  var value);

     set have;

     array vars (list of your analysis variables);

    length variable $32;

     do i = dim(vars);

          call vname( vars,variable);

          value = vars;

          output;

     end;

run;

This creates a data set with year, the name of the variable as the value of a string variable and the value.

Then sandwich the below code in appropriate ODS PDF or RTF call. Defaults to one table per page.

proc tabulate data=want;

     class variable year;

     var value;

     table variable,  /* as first item this will be table level*/

              value *(n mean max min std),  /* or which ever statistics you want these will be row variables)

               year ; /* year would be column variable, if you want year as the row, then reverse the order of these*/

run;


Contributor
Posts: 30

Re: proc means with class YEAR and more variables, how to make individual tables for each variable?

Thank you for the help, everybody! I have now found a satisfying solution.

Ask a Question
Discussion stats
  • 6 replies
  • 247 views
  • 4 likes
  • 4 in conversation