BookmarkSubscribeRSS Feed
parneet01
Calcite | Level 5

hi i am looking to get total of two variables in seprate column like as shown in below format . also looking to get age/total %.  can anyone help please thanks

 

PROC TABULATE data=sashelp.class  missing format=comma29.;
class  sex;
var age height;
table sex ='eligible/ineligible' all = 'Total', all='Tota' (age height )*SUM=''/box='DATA' ;

run;

tabulate.PNG

1 REPLY 1
ballardw
Super User

Thank you for using a SAS supplied data set we can run code.

Tabulate does not do sums of different variables. You would need Proc report for that .

 

proc report data=sashelp.class;
   column sex age height tot totpct ;
   define sex /group;
   define age / sum;
   define height/ sum;
   define tot /Computed "Total";
   define totpct/Computed format=percent8.1;
   compute tot;
      tot = age.sum +height.sum;
   endcomp;
   compute totpct;
      totpct = age.sum/(age.sum+height.sum);
   endcomp;
   rbreak after/summarize;
run;

Or use proc summary to summarize the age and height by sex in a data step first and precalculate the row summaries. Note that Proc summary will provide an overall summary.

proc summary data=sashelp.class;
   class sex;
   var age height;
   output out=work.summary sum=;
run;

The _type_ variable in the output data indicates which combinations of the class variables appear. You could use this in a data step to calculate the sum of age and height plus the desired percent for each row.

Then use Proc Print to display the result.

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
  • 1 reply
  • 341 views
  • 3 likes
  • 2 in conversation