Skip to content
TheChatArchiveThe Chat Archive
Metallama-4-maverick-03-26-experimental· MetaHugging Face LMArena Human Preference 140K

Can you help me rework this SAS report? proc report data=allscreenings nowd headline;…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-3-7-sonnet-20250219-thinking-32k’s answer.
  1. User

    Can you help me rework this SAS report?

    proc report data=all_screenings nowd headline;

    column siteNumber siteName screentype screentot screen7days consenttot eligible percent; 

    define siteNumber / display 'Site Number';

    define siteName / display 'Site Name';

    define screentype / display 'Type';

    define screentot / sum 'Screened';

    define screen7days / sum 'Screened in Previous Week';

    define consenttot / sum 'Eligible Phase I';

    define eligible / sum 'Eligible Phase II';

    define percent / computed 'Percent Eligible Phase II of Screened' f=percent9.1;

    COMPUTE percent;

    if screentot.sum > 0 then percent = eligible.sum/screentot.sum;

    else percent = 0;

    ENDCOMP;

    COMPUTE after;

    siteName="Grand Total";

    screentype = "(All Screenings)";

    ENDCOMP;

    rbreak after / summarize style=[font_weight=bold];

    run;

    What I'd like to do is add 3 lines above the 'Grand Total'. One subtotal for each screening type (Initial, Rescreen 1, Rescreen 2)

    Can I do that in the report step or do I need to do more processing on my data first?

  2. Meta Assistant

    A classic SAS reporting challenge!

    You can achieve this within the PROC REPORT step using the BREAK statement, without needing to preprocess your data. Here's the modified code:

    proc report data=all_screenings nowd headline;
      column siteNumber siteName screentype screentot screen7days consenttot eligible percent; 
    
      define siteNumber / display 'Site Number';
      define siteName / display 'Site Name';
      define screentype / group 'Type'; /* Changed to GROUP */
      define screentot / sum 'Screened';
      define screen7days / sum 'Screened in Previous Week';
      define consenttot / sum 'Eligible Phase I';
      define eligible / sum 'Eligible Phase II';
      define percent / computed 'Percent Eligible Phase II of Screened' f=percent9.1;
    
      COMPUTE percent;
        if screentot.sum > 0 then percent = eligible.sum/screentot.sum;
        else percent = 0;
      ENDCOMP;
    
      /* Subtotal breaks for each screening type */
      break after screentype / summarize skip style=[font_weight=bold];
    
      /* Grand Total */
      COMPUTE after;
        siteName="Grand Total";
        screentype = "(All Screenings)";
      ENDCOMP;
      rbreak after / summarize style=[font_weight=bold];
    
    run;
    

    Here's what changed:

    1. I modified the define screentype statement to GROUP instead of DISPLAY. This tells PROC REPORT to treat screentype as a grouping variable, which allows us to create subtotals.
    2. I added a BREAK statement: break after screentype / summarize skip style=[font_weight=bold];
      • after screentype specifies that we want to break after each group of screentype values (i.e., after each screening type).
      • summarize calculates the subtotals for the numeric columns (screentot, screen7days, consenttot, eligible, and percent).
      • skip inserts a blank line after each subtotal for readability.
      • style=[font_weight=bold] formats the subtotal lines in bold font.

    The RBREAK statement remains unchanged, still generating the Grand Total at the end.

    With these modifications, your report will now display:

    1. Detail rows for each site and screening type
    2. Subtotals for each screening type (Initial, Rescreen 1, Rescreen 2) with bold formatting and a blank line after each
    3. Grand Total at the end, also in bold

    Run this code, and you should see the desired output!

    Tips:

    • If you want to customize the subtotal labels (e.g., "Initial Screenings Total" instead of just the type value), you can use the RBREAK statement with a COMPUTE block, similar to what you did for the Grand Total. However, this requires more advanced coding.
    • If your screentype values have a specific order, consider adding an ORDER statement before the DEFINE statements to control the sorting: order screentype; (e.g., to ensure "Initial" comes before "Rescreen 1").

    Enjoy your enhanced report!

  3. User

    That's close, but what I really want is the 3 total lines at the bottom (all 3 of them just above Grand Total)

  4. Meta Assistant

    In that case, you can use the RBREAK statement with the OLDSUMMARY option to create a "rolling summary" that accumulates subtotals for each screentype group, and then displays them all at the end, just before the Grand Total.

    Here's the modified code:

    proc report data=all_screenings nowd headline;
      column siteNumber siteName screentype screentot screen7days consenttot eligible percent; 
    
      define siteNumber / display 'Site Number';
      define siteName / display 'Site Name';
      define screentype / group 'Type';
      define screentot / sum 'Screened';
      define screen7days / sum 'Screened in Previous Week';
      define consenttot / sum 'Eligible Phase I';
      define eligible / sum 'Eligible Phase II';
      define percent / computed 'Percent Eligible Phase II of Screened' f=percent9.1;
    
      COMPUTE percent;
        if screentot.sum > 0 then percent = eligible.sum/screentot.sum;
        else percent = 0;
      ENDCOMP;
    
      /* Create rolling subtotals for each screentype */
      rbreak after screentype / olddummary skip style=[font_weight=bold];
    
      /* Grand Total */
      COMPUTE after;
        siteName="Grand Total";
        screentype = "(All Screenings)";
      ENDCOMP;
      rbreak after / summarize style=[font_weight=bold];
    
    run;
    

    Here's what changed:

    1. I replaced the BREAK statement with an RBREAK statement: rbreak after screentype / olddummary skip style=[font_weight=bold];
      • after screentype still specifies that we want to break on the screentype variable.
      • olddummary (short for "old summary") tells PROC REPORT to accumulate subtotals for each screentype group and display them all at the end, rather than after each group.
      • skip inserts a blank line after each subtotal line for readability.
      • style=[font_weight=bold] formats the subtotal lines in bold font.

    The second RBREAK statement remains unchanged, still generating the Grand Total at the very end.

    With this modification, your report will now display:

    1. Detail rows for each site and screening type
    2. At the bottom:
      • Subtotal for "Initial"
      • Subtotal for "Rescreen 1"
      • Subtotal for "Rescreen 2"
      • Grand Total (in bold)

    All three subtotal lines will appear just above the Grand Total, as desired!

    Tips:

    • The order of the subtotal lines will match the order of the screentype values in your data. If you want a specific order (e.g., "Initial", "Rescreen 1", "Rescreen 2"), consider sorting your data beforehand using PROC SORT or adding an ORDER statement in PROC REPORT.
    • If you want custom labels for the subtotal lines (e.g., "Initial Screenings Total"), you'll need to preprocess your data to include a new variable with those labels, and then use that variable in the RBREAK statement.

    Run this code, and you should see the subtotals exactly where you want them!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.