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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1087 views
  • 3 likes
  • 3 in conversation