Calcite | Level 5

## Reordering rows in a dataset

Hello, I'm bit new in SAS. I have a dataset made via a proc report like this one:

Central         Generation

Central1        394

Central2        8384

Central3        384

Total H          (sum)

Central4        2342

Central5        2321

Total T           (sum)

Total Agent   (total sum)

What I want is change the position of the 'Total' rows to the beggining of each block. The original dataset has 52 of these blocks, I mean, somethig like this

Central         Generation

Total Agent   (total sum)

Total H          (sum)

Central1        394

Central2        8384

Central3        384

Total T           (sum)

Central4        2342

Central5        2321

Is there any way to perform this? Thanks in advance.

3 REPLIES 3
Super User

## Re: Reordering rows in a dataset

Not easily. Add another variable that contains your sort order which has to be somewhat manual and then sort it. In general, this is why there's a recommendation to not store totals and subtotals in data sets but calculate them in reporting procedures such as PROC REPORT.
Super User

## Re: Reordering rows in a dataset

@MathJack901015 wrote:

Hello, I'm bit new in SAS. I have a dataset made via a proc report like this one:

Central         Generation

Central1        394

Central2        8384

Central3        384

Total H          (sum)

Central4        2342

Central5        2321

Total T           (sum)

Total Agent   (total sum)

What I want is change the position of the 'Total' rows to the beggining of each block. The original dataset has 52 of these blocks, I mean, somethig like this

Central         Generation

Total Agent   (total sum)

Total H          (sum)

Central1        394

Central2        8384

Central3        384

Total T           (sum)

Central4        2342

Central5        2321

Is there any way to perform this? Thanks in advance.

You might be able to do the "report" with proc tabulate as that allows group totals to come first.

```proc tabulate data=sashelp.class;
class age sex;
table all='Overall Count' ( age='')*(all='Age Count' sex=''),
n;
run;```

Proc tabulate also creates output data sets but working with them may be a tad daunting.

Super User

## Re: Reordering rows in a dataset

Use

break before cental/summarize;

rbreak before cental/summarize;

Discussion stats
• 3 replies
• 2412 views
• 2 likes
• 4 in conversation