BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
art297
Opal | Level 21

You can add  one or more 'by' variables to almost every SAS proc.

Reeza
Super User

If you're doing unique counts you probably want to look at proc freq or proc sql with count distinct instead of proc means.

Generally its a two step proc freq procedure or a single proc sql procedure. Depending on the data of course.


thdang
Calcite | Level 5

Thank you. But what I also mean is that before I have 1 summary table for the whole data set (30 years of data). Is that also possible to have several tables of summary each for 5 years interval (thus 6 tables)?

Reeza
Super User

Then Art is correct, add a by statement.

art297
Opal | Level 21

You will probably also need a format to define your groups.  If you use a by statement you will get the desired groupings.  If you use a class statement instead (i.e., replace the word by with the word class), you will get an extra line that shows the grand totals:

data have;

  do year=1983 to 2012;

    do i=1 to 19;

      set sashelp.class point=i;

      output;

    end;

  end;

  stop;

run;

proc format;

  value years

  1983-1987='1983-1987'

  1987-1992='1987-1992'

  1993-1997='1993-1997'

  1998-2002='1998-2002'

  2003-2007='2003-2007'

  2008-2012='2008-2012'

  ;

run;

proc means data=have min max mean median stackods;

  var height weight;

  weight age;

  by year;

  format year years.;

  output out=sample_summary median= mean= min= max= stddev= /autoname;

run;

thdang
Calcite | Level 5

Thank you very much!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 20 replies
  • 4127 views
  • 7 likes
  • 5 in conversation