Help using Base SAS procedures

Why the order of the output is coming somewhat wrongly in Proc report?

Reply
Contributor
Posts: 49

Why the order of the output is coming somewhat wrongly in Proc report?

Can any one help?

Data one;

INPUT ZIP CTY $ VAR :$15. SALES;

CARDS;

52423 Scott Merlot 186.     

52423 Scott Chardonnay 156.61

52423 Scott Zinfandel 35.5  

52423 Scott Merlot 55.3     

52388 Scott Merlot 122.89   

52388 Scott Chardonnay 78.22

52388 Scott Zinfandel 15.4  

52200 Adams Merlot 385.51   

52200 Adams Chardonnay 246  

52200 Adams Zinfandel 151.1 

52200 Adams Chardonnay 76.24

52199 Adams Merlot 233.03   

52199 Adams Chardonnay 185.22

52199 Adams Zinfandel 95.84 

;

proc report data=one nofs headline headskip;

column cty zip var sales;

define var / display;

define sales / order;

run;

Occasional Contributor
Posts: 9

Re: Why the order of the output is coming somewhat wrongly in Proc report?

Posted in reply to devarayalu

Give the informat for sales also like 6.2.

Occasional Contributor
Posts: 9

Re: Why the order of the output is coming somewhat wrongly in Proc report?

Posted in reply to devarayalu

give informat to sales as sales:6.2

Super User
Super User
Posts: 7,042

Re: Why the order of the output is coming somewhat wrongly in Proc report?

Posted in reply to devarayalu

You need to tell it to sort by the actual value and not the displayed text string's value.

define sales / order order=internal ;

SAS Super FREQ
Posts: 8,864

Re: Why the order of the output is coming somewhat wrongly in Proc report?

Hi:

  In addition to Tom's suggestion, depending on what you mean by the "order coming out somewhat wrongly", there are other options you can use in your DEFINE statement. For example, if you want the SALES in DESCENDING order, that is an option you can list on the DEFINE statement. ORDER= can take 4 values: FREQ, FORMATTED, INTERNAL and DATA.  I rarely use FREQ or FORMATTED. I find that either INTERNAL or DATA suits most of what I need to do.

  Here are some other examples to compare.

cynthia

Data one;

INPUT ZIP CTY $ VAR :$15. SALES;

CARDS;

52423 Scott Merlot 186.    

52423 Scott Chardonnay 156.61

52423 Scott Zinfandel 35.5 

52423 Scott Merlot 55.3    

52388 Scott Merlot 122.89  

52388 Scott Chardonnay 78.22

52388 Scott Zinfandel 15.4 

52200 Adams Merlot 385.51  

52200 Adams Chardonnay 246 

52200 Adams Zinfandel 151.1

52200 Adams Chardonnay 76.24

52199 Adams Merlot 233.03  

52199 Adams Chardonnay 185.22

52199 Adams Zinfandel 95.84

;

run;

  

ods listing close;

ods html file='c:\temp\show_order.html' style=sasweb;

proc report data=one nofs;

title '1) ORDER (simple) is ASCENDING';

column cty zip var sales;

define var / display;

define sales / order f=6.2;

run;

    

proc report data=one nofs;

title '2) ORDER (simple) is DESCENDING';

column cty zip var sales;

define var / display;

define sales / order descending f=6.2;

run;

     

     

proc report data=one nofs;

title '3) ORDER is DATA gives input data order';

column cty zip var sales;

define var / display;

define sales / order f=6.2 order=data;

run;

  

proc report data=one nofs;

title '4) ORDER is internal';

column cty zip var sales;

define var / display;

define sales / order f=6.2 order=internal;

run;

  

proc report data=one nofs;

title '5) ORDER for multiple vars note that ZIP is still unordered';

column cty zip var sales;

define cty / order;

define var / display;

define sales / order f=6.2;

run;

  

proc report data=one nofs;

title '6) ORDER for multiple vars DESCENDING for CTY';

column cty zip var sales;

define cty / order DESCENDING;

define var / display;

define sales / order f=6.2;

run;

 

ods html close;

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