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
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
But I want an ordered output of population variable
How can I get that?
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.