BookmarkSubscribeRSS Feed
Eva
Quartz | Level 8 Eva
Quartz | Level 8

Dear all,

I have a proc report with a computed variable for which I need a total in the last row.

options missing = '';

proc report data=mydata;

     column firstfield hiddenfield myfield [some more fields];

     define firstfield / display noprint;

     define hiddenfield / display noprint;

     define myfield / computed;

     [some more fields]

     compute myfield;

             if firstfield eq 1 then do;

                      myfield = hiddenfield;

             end;

             else do;

                      myfield = . ;

             end;   

     endcomp;

run;

The data behind this looks like this (first 2 columns - and the third column should be the computed field):

the idea behind this is to suppress repeated values and sum in the total only the distinct values per firstfield = 1

firstfieldhiddenfieldmyfield
19292
092
092
1236236
0236
0236
0236

Now when I do a rbreak the total for hiddenfield is 3*92 + 4*236. But for myfield I need the total 1*92 + 1*236.

Unfortunaltely the SAS automatism does a missing value. I'd love to have the rbreak just as a sum of the myfield values.

The only idea I had was using the trick of aggregating the values by temporary variables:

compute before;

     mytotal = 0;

endcomp;

compute myfield;

     mytotal = myfield + mytotal;

     if _break_ eq "_RBREAK_ then do;

         myfield = mytotal;

     end;

endcomp;

Does anybody know some other solution?

Best wishes

Eva

1 REPLY 1
Cynthia_sas
SAS Super FREQ

Hi,

   If you know that the values in HIDDENFIELD will ALWAYS be the same, then you could use the MEAN statistic to generate the total you want without creating the MYFIELD column.

  But, since you are hiding the values anyway, why not just change HIDDENFIELD in a DATA step program (or create a new variable) using FIRST. processing so you only keep the first value, then your sum will work correctly? (if you define your variable as SUM, not DISPLAY).

cynthia

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 571 views
  • 0 likes
  • 2 in conversation