Getting count and total count to work in proc print

Reply
New Contributor
Posts: 3

Getting count and total count to work in proc print

I'm trying to get a total count as well as a break count by login_user_id. From what I found on the web, the following code should work, but it does not give me a total count. Could someone please advise me on what I'm missing?

proc print data=R_WData.Mapext4 label sumlabel n='Login Count = ' 'Total Login Count = ';

   by login_user_id;

   id login_user_id;

  var Fname Lname login_user_id Activity_attempt_dttm;

   title1 "Users for a Selected Time Period";

     

run;

PROC Star
Posts: 7,487

Re: Getting count and total count to work in proc print

Posted in reply to tbagger70

You are missing a sum statement, but I don't think that will help you with this dataset, as you don't have anything to sum.

If you had a numeric variable for which a sum would be relevant, e.g., time_spent, then you could use something like:

proc print data=R_WData.Mapext4 label sumlabel n='Login Count = ' 'Total Login Count = ';

   by login_user_id;

   id login_user_id;

   var Fname Lname login_user_id Activity_attempt_dttm;

  sum time_spent;

   title1 "Users for a Selected Time Period";

run;


and you would then obtain what you are looking for.


Super User
Posts: 19,851

Re: Getting count and total count to work in proc print

Posted in reply to tbagger70

I think you need to use proc report or tabulate instead of proc print for this.

PROC Star
Posts: 7,487

Re: Getting count and total count to work in proc print

: If the OP doesn't have any variable to sum, I agree with you that tabulate or report may be needed.

However, I find it interesting that including a sum statement, with no variables, doesn't product any error, but doesn't honor the 2nd title for the n= option.

Since every time I've submitted anything to the SAS ballot, I've gotten an unsatisfactory response, I won't submit one in this case.  However, I'd call this a bug (actually two discrepancies in the manual).  One or more variables are supposedly required with a sum statement, but apparently aren't.  And, when a sum statement is included, proc print is supposed to do the total sum and honor the secondary n= variable label line.

Is anyone from SAS reading this?

Super User
Super User
Posts: 7,074

Re: Getting count and total count to work in proc print

Posted in reply to tbagger70

I think that the issue is using the combination of BY and ID variables.  This has always been a special case for PROC PRINT. Doing that will defeat the SUMLABEL option.

Ask a Question
Discussion stats
  • 4 replies
  • 244 views
  • 0 likes
  • 4 in conversation