BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10


data test (keep=loan process_date);

set test2;

by ln_no;

run;

produces dataset results

loan           process_date

1                11/19/2013

2                11/19/2013

3                10/6/2013

4                10/6/2013

I converted the process_date to a character to use in as a header

data test3;

set test;

Completion=put(process_date,mddyy10.);

run;

Now I do a proc tabulate to view process_date as a column header and count the number of loans

proc tabulate data= test3 out=test4;

class  Completion;;

var  loan;

table  Completion;

run;

Results in

10/6/2013     11/19/2013

   2                    2

Now I want to add a bottom line row total and an across column total like this

               10/6/2013     11/19/2013            Total

                  2                    2                       4

Total           2                     2                       4

How can I accomplish this.  Is it best to use another descriptive statistic

2 REPLIES 2
Reeza
Super User

Usually the ALL keyword will get you there. See the examples in the documentation Smiley Happy

Base SAS(R) 9.3 Procedures Guide, Second Edition

Cynthia_sas
SAS Super FREQ

Hi, and in addition to Reeza's good suggestion to look in the doc for how to use ALL, there are a couple of other points:

1) you do not need to make your date variable a character variable for it to be in the column headers. For example, SASHELP.PRDSALE has a MONTH variable that is actually a date value. For either report created with the code below, MONTH is numeric and is formatted with DATE9. -- still a number. Using MONTH in the CLASS statement is what tells TABULATE to use it for column headers and not for statistics.

2) See Report 1 output. The final "row" total doesn't make sense for Report 1, but makes more sense for Report 2.

3) Look specifically in the doc for how to use the CLASS and VAR statements as well as the ALL keyword for totals or summary statistics.

Cynthia

title; footnote;

ods _all_ close;

 

** MONTH is numeric variable representing the DATE, formatted by default to MONNAME3.;

** change the format to DATE9. to see the date values;

ods html file='c:\temp\usetab1_col.html' style=sasweb;

proc tabulate data= sashelp.prdsale;

title '1) Bottom line Row Total does not make sense in this table';

where month le '30jun1993'd;

class  month;

table n all, month all/ row=float;

format month date9.;

keylabel all='Total' n=' ';

keyword all / style={vjust=b};

label month='Date';

run;

    

proc tabulate data= sashelp.prdsale;

title '2) With a Row dimension, a grand total makes more sense';

where month le '30jun1993'd;

class  product month;

table  product all,

       month*n all*n /box='2 dimension table' ;

format month date9.;

keylabel all='Total' n=' ';

keyword all / style={vjust=b};

label month='Date';

run;

ods html close;

title; footnote;


compare_two_tabulates.png

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!

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.

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
  • 2 replies
  • 710 views
  • 0 likes
  • 3 in conversation