BookmarkSubscribeRSS Feed
devarayalu
Fluorite | Level 6

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

3 REPLIES 3
Cynthia_sas
SAS Super FREQ

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

devarayalu
Fluorite | Level 6

But I want an ordered output of population variable

How can I get that?

Cynthia_sas
SAS Super FREQ

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 3555 views
  • 3 likes
  • 2 in conversation