BookmarkSubscribeRSS Feed
tbagger70
Calcite | Level 5

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;

4 REPLIES 4
art297
Opal | Level 21

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.


Reeza
Super User

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

art297
Opal | Level 21

: 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?

Tom
Super User Tom
Super User

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1929 views
  • 0 likes
  • 4 in conversation