Help using Base SAS procedures

Why the error is coming in Proc Report?

Reply
Contributor
Posts: 49

Why the error is coming in Proc Report?

PROC REPORT data=sql.countries nofs headline headskip;

TITLE'Population of Large Countries Grouped by Continent';

column continent population, sum;

define continent / group;

define population / order f=comma20.;

run;

ERROR: An ORDER variable appears above or below other report items.

       Name                              Usage

       --------------------------------  --------

       Population                        ORDER

       sum                               STATISTIC

SAS Super FREQ
Posts: 8,868

Re: Why the error is coming in Proc Report?

Posted in reply to devarayalu

Hi:

  If POPULATION is a numeric variable and you want the SUM of POPULATION, then ORDER is the incorrect usage for POPULATION. Instead, you should try the SUM statistic as the USAGE. Your use of a comma in the COLUMN statement implies that you are crossing or nesting POPULATION with SUM, which is technically not necessary, if you change your usage as shown:

PROC REPORT data=sql.countries nofs;

  TITLE 'Population of Large Countries Grouped by Continent';

  column continent population;

  define continent / group;

  define population / sum f=comma20.;

run;

However, given your TITLE, I would also expect to see a COUNTRY variable on the report. Or else, does CONTINENT also contain a COUNTRY name? But since you didn't explain your data it's hard to understand what your program is trying to accomplish.

cynthia

Contributor
Posts: 49

Re: Why the error is coming in Proc Report?

Posted in reply to Cynthia_sas

But I want an ordered output of population variable

How can I get that?

SAS Super FREQ
Posts: 8,868

Re: Why the error is coming in Proc Report?

Posted in reply to devarayalu

Hi:

  You cannot summarize a variable using PROC REPORT and then also use that variable as an ordering variable. You did not say whether your data was already summarized or not, so I'm not sure of what approach to recommend. Basically, if your data are NOT summarized, you need to make 2 passes through your data. A first pass to make a summarizing pass and to create a variable to use for ordering.Then, if you want to summarize and order, you can use your "extra" variable or ordering variable to apply order, like descending order.

  If your data are already summarized, then you have an easier time of it. PROC REPORT allows you to create an "alias" for an existing variable and so you can use the variable values for ordering and then use the same variable under an alias for display purposes. See the code sample below.

cynthia

data pop;

  infile datalines;

  input Continent $ Population;

return;

datalines;

North 1736142

South 2173552

East  3841291

West  4623657

;

run;

 

ods html file='c:\temp\sum_and_order.html';

title 'Already summarized';

proc report data=pop nowd;

  column population continent population=disppop;

  define population / order descending noprint;

  define continent / order;

  define disppop / sum 'Population' f=comma12.;

  rbreak after / summarize;

run;

ods html close;

Ask a Question
Discussion stats
  • 3 replies
  • 859 views
  • 3 likes
  • 2 in conversation