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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1126 views
  • 0 likes
  • 4 in conversation