Sample 25323: Grouped or Sorted Observations, Chapter 10
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/**************************************************************/
/* S A S S A M P L E L I B R A R Y */
/* */
/* NAME: BUG10U01 */
/* TITLE: Grouped or Sorted Observations, Chapter 10 */
/* PRODUCT: BASE */
/* SYSTEM: ALL */
/* KEYS: DOC DATASTEP PRINT SORT VAR SET BY FIRST. LAST. */
/* NODUP */
/* PROCS: PRINT SORT */
/* DATA: */
/* */
/* SUPPORT: UPDATE: */
/* REF: SAS Language and Procedures: Usage */
/* MISC: */
/* */
/**************************************************************/
/* For simplicity the infile statement has been removed and */
/* the raw data is being read into this step via a cards */
/* statement. */
options ls=72;
title;
data type;
input country $ 1-11 tourtype $ 13-24 nights
landcost vendor $;
cards;
Spain architecture 10 510 World
Japan architecture 8 720 Express
Switzerland scenery 9 734 World
France architecture 8 575 World
Ireland scenery 7 558 Express
New Zealand scenery 16 1489 Southsea
Italy architecture 8 468 Express
Greece scenery 12 698 Express
;
run;
proc print data=type;
title 'Data Set TYPE';
run;
proc sort data=type out=type2;
by tourtype;
run;
proc print data=type2;
var tourtype country nights landcost vendor;
title 'The Simplest Sort--One Variable, Default Order of Groups';
run;
proc sort data=type out=type3;
by tourtype vendor landcost;
run;
proc print data=type3;
var tourtype vendor landcost country nights;
title 'Observations Grouped by Type of Tour, Vendor, and Price';
run;
proc sort data=type out=type4;
by descending tourtype vendor landcost;
run;
proc print data=type4;
var tourtype vendor landcost country nights;
title 'Descending and Ascending Orders';
run;
proc sort data=type out=type5;
by tourtype landcost;
run;
proc print data=type5;
var tourtype landcost country nights vendor;
title 'Tours Arranged by TOURTYPE and LANDCOST';
run;
data temp;
set type5;
by tourtype;
frsttour=first.tourtype;
lasttour=last.tourtype;
run;
proc print data=temp;
var country tourtype frsttour lasttour;
title 'Representing FIRST.TOURTYPE and LAST.TOURTYPE';
run;
proc sort data=type out=type5;
by tourtype landcost;
run;
data lowcost;
set type5;
by tourtype;
if first.tourtype;
run;
proc print data=lowcost;
title 'Least Expensive Tour for Each Type of Tour';
run;
proc sort data=type out=type6;
by country;
run;
proc print data=type6;
title 'Alphabetical Order by Country';
run;
data dupobs;
input country $ 1-11 tourtype $ 13-24 nights
landcost vendor $;
cards;
Spain architecture 10 510 World
Japan architecture 8 720 Express
Switzerland scenery 9 734 World
Switzerland scenery 9 734 World
France architecture 8 575 World
Ireland scenery 7 558 Express
New Zealand scenery 16 1489 Southsea
Italy architecture 8 468 Express
Greece scenery 12 698 Express
;
run;
proc print data=dupobs;
title 'Data Set DUPOBS';
run;
proc sort data=dupobs out=fixed noduplicates;
by country;
run;
proc print data=fixed;
title 'Removing a Duplicate Observation with PROC SORT';
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
These samples are from the "SAS Language and Procedures: Usage" book (No. 56075), Chapter 10.
For output and additional information on the samples refer to this book.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step Data Management ==> Manipulation and Transformation ==> BY-group processing SAS Reference ==> Procedures ==> SORT
|
| Date Modified: | 2005-12-08 11:34:43 |
| Date Created: | 2005-05-23 13:45:58 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |