BookmarkSubscribeRSS Feed
bananah13
Fluorite | Level 6

*Update with SAS sample data set. Cannot link to github on my computer.

 

Hello,

 

How do I create a proc report that shows multiple variables and the sum of their values by the grouped variable 'agency'? The below code creates the pasted table, but it does not show n values of proceeding variable, rather it shows the n value of addressx across all of the n columns (note how the all have the same value sums). Except for agency, each variable has 2 values (1 and 2). They are all formatted 1=Missing or Unknown ; 2=Complete. I would prefer not to have to make a separate report for each variable. 

 

Second, I would like the % column to show the total of the variable by agency rather than the column totals, which is what is showed now. For examples, For the variable 'First Name', % column under the row 'starlight' would show: 83.3% (749/901) for 'complete' and 16.8% (152/901) for 'missing or unknown' rows. Also written as: [first name 'complete' by agency' (numerator)/first name 'total' by agency (denominator)] for row with value 'complete'.  [First name 'missing or unknown' by agency' (numerator)/first name 'total' by agency (denominator)] for row with value 'missing or unknown'.  

 

 

Code:

proc report data=QC.LEOClient_NewVar&SYSDATE missing ;
  column agency (firstnameX n pctn) (lastnameX n  pctn ) (addressx n pctn) ;

    define agency/group format=agencyf. "Agency";
    define firstnameX / group format=firstnamex. "First Name" ;

    define lastnameX / group format=lastnamex. "Last Name" ;

    define addressx / group format=addressx. "Address" ;

    define pctn / "%" f=percent10.3;

run;

 

Output:

AgencyFirst Namen%Last Namen%Addressn%
StarlightComplete7497.912%Complete7497.912%Complete7497.912%
  1521.606% 1521.606%Missing or Unknown1521.606%
 Missing or Declined420.444%Missing or Declined420.444%Missing or Unknown420.444%
SunshineComplete1271.342%Complete1271.342%Complete1271.342%
  40.042% 40.042%Missing or Unknown40.042%
 Missing or Declined20.021%Missing or Declined20.021%Missing or Unknown20.021%
MoonbeamComplete420.444%Complete420.444%Complete420.444%
  30.032% 30.032%Missing or Unknown30.032%
 Missing or Declined10.011%Missing or Declined10.011%Missing or Unknown10.011%
2 REPLIES 2
ballardw
Super User

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software or policies. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.

 

When discussing percentages you need to be very clear what the numerator and denominator are and where they come from. I'm not sure that I actually follow your description of what percentages you want.

Cynthia_sas
SAS Super FREQ

Hi, and, to add to what @ballardw suggested, even if somebody was kind enough attempt to make some fake data, since you did not provide the user-defined formats, or specify the ODS destination, they could not run your code.

Cynthia_sas_0-1673664142181.png

 

  It almost seems to me that you want TABULATE and not REPORT for this anyway because with TABULATE, you have more percent statistics than you have available with REPORT.

Cynthia

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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