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

Hi Expert,

I'm new with SAS programming. I'd sample code as follow and it works. It calculate the mean for height base on age.

My question now is, from the table "Class" in SASHelp, there is also for weight. How can i include the height and weight to be shown on the report?

Hope any expert in sas programming can help.

Sample code:-

=====================================

data class;                                                  

   set sashelp.class;                                        

   h2=height*2;                                              

run;                                                         

                                                             

proc tabulate data=class format=8.1;                         

   class sex age;                                            

   var height h2;                                            

   table age, sex*(height*mean) (height h2)*mean;            

run;                                                         

                                                             

proc report data=sashelp.class nowd headline;                

   col age sex,height height h2;                             

   define age / group;                                       

   define sex / across;                                      

   define height  / mean format=8.1;                         

   define h2 / computed format=8.1;                          

                                                             

   compute h2;                                               

       h2= _c4_ * 2;                                         

   endcomp;                                                  

run;

===========================

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

How about:

proc report data=sashelp.class nowd headline;                
  col age sex,(height weight) height height=h2 weight weight=w2;                             
  define age / group;                                       
  define sex / across;                                      
  define height  / mean format=8.1;                         
  define weight  / mean format=8.1;                         
  define h2 / mean format=8.1 'h2';
  define w2 / mean format=8.1 'w2';
  compute h2;                                               
      h2=h2 * 2;
  endcomp;
compute w2;                                               
      w2=w2 * 2; 
  endcomp;                                                  
run;


Ksharp

View solution in original post

4 REPLIES 4
Astounding
PROC Star

Regarding PROC TABULATE only, you have to take two steps to include WEIGHT.  First, add WEIGHT to the VAR statement:

var height h2 weight;

Second, place WEIGHT in the TABLE statement in the spot(s) where you would like it to appear on your table.  One possibility:

table age, sex*(height weight) * mean (height h2)*mean;

Experiment a bit to get a feel for it.

mikesatriaevo
Fluorite | Level 6

Hi Astouding,

Thanks for the advise. I'd change the code and follow your suggestion. but my proc report seem to be unable to display correctly.

data class;                                                  

  set sashelp.class;                                        

  h2=height*2;

  w2=weight*2;

run;                                                         

                                                            

proc tabulate data=class format=8.1;                         

  class sex age;                                            

  var height h2 weight w2;

  table age, sex*(height weight*mean) (height h2 weight w2)*mean;            

run;

                                                            

proc report data=sashelp.class nowd headline;                

  col age sex, height weight height h2 weight w2;                             

  define age / group;                                       

  define sex / across;                                      

  define height  / mean format=8.1;                         

  define weight  / mean format=8.1;                         

  define h2 / computed format=8.1;

  define w2 / computed format=8.1;

  compute h2;                                               

      h2= _c4_ * 2;

  endcomp;

compute w2;                                               

      w2= _c4_ * 2; 

  endcomp;                                                  

run;

Ksharp
Super User

How about:

proc report data=sashelp.class nowd headline;                
  col age sex,(height weight) height height=h2 weight weight=w2;                             
  define age / group;                                       
  define sex / across;                                      
  define height  / mean format=8.1;                         
  define weight  / mean format=8.1;                         
  define h2 / mean format=8.1 'h2';
  define w2 / mean format=8.1 'w2';
  compute h2;                                               
      h2=h2 * 2;
  endcomp;
compute w2;                                               
      w2=w2 * 2; 
  endcomp;                                                  
run;


Ksharp

mikesatriaevo
Fluorite | Level 6

Thanks SAS Expert. it really help.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 1377 views
  • 3 likes
  • 3 in conversation