Sorting or grouping in proc print

Reply
Occasional Contributor
Posts: 10

Sorting or grouping in proc print

I am new to coding in SAS so I was wondering if someone could help me.  I am on the right track but I would like to have my output data grouped by category and a rank field ~ This works for grouping my output by category in alpha order but how do I change this to Rank order (1, 2, 3, 4, 5,....) but still grouped by category. Basiclly I want my output to be in Rank order but grouped by Category....  I hope this makes sense.  

Proc Sort data = work.'fixing null values'n out = work.'fixing null values'n;

  by  Category;

run;

Proc Print data = work.'fixing null values'n n= 'Report' noobs sumlabel;

  var Rank POS Category Rev Volume 'paid amount'n;

  by Category;

  sumby category;

Run;

Grand Advisor
Posts: 10,233

Re: Sorting or grouping in proc print

Proc sort; by category rank;run;

Occasional Contributor
Posts: 10

Re: Sorting or grouping in proc print

Can you show me where you would put that in my code?

SAS Employee
Posts: 340

Re: Sorting or grouping in proc print

Proc Sort data = work.'fixing null values'n out = work.'fixing null values'n;

  by  Category rank;

run;

Proc Print data = work.'fixing null values'n n= 'Report' noobs sumlabel;

  var Rank POS Category Rev Volume 'paid amount'n;

  by Category;

  sumby category;

Run;

Occasional Contributor
Posts: 10

Re: Sorting or grouping in proc print

The problem I have with putting the rank right there is that the rank field is numeric (1, 2, 3, 4, 5, 6, ....) The table is a summary table that is one line but has groupings (category).  Each category has another distinct column called the Rev - which is different per line. 

Rank     Category

1          Inpatient

2          Inpatient    

3          Inpatient

4          Outpatient

5          Outpatient

6          Outpatient

So by putting rank where you suggested does not work because the output looks something like this:

1     Inpatient     Total paid

2      Inpatient      Total Paid

3     Inpatient      Total Paid

Etc... Etc...

When I want the output to be in Rank order (ascending order) grouped by the categories

1     Inpatient

2      Inpatient

3      Inpatient

                Inpatient Total Paid

I hope this makes sense.

Grand Advisor
Posts: 17,411

Re: Sorting or grouping in proc print

Can you post a bit more of your sample data and what you want the output to look like?

Ask a Question
Discussion stats
  • 5 replies
  • 220 views
  • 0 likes
  • 4 in conversation