LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (February 2005, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 20 Feb 2005 07:15:15 -0500
Reply-To:     "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Subject:      Re: Newbie Question on how to subset a data set by unique values
              of a variable

enstrophy wrote: > Hi, > I'm new to SAS and am confronted by a task of subsetting > a data set accroding to unique values of a given variable. > For example, for the following data set:

Welcome to SAS and SAS-L !

> Label Price > aa 1.2 > bb 2.4 > aa 3.0 > cc 2.4 > cc 1.5 > > the objective is to create several data sets, each with > a unique Label, i.e.,

Often a dubious objective.

> > data set 1: > Label Price > aa 1.2 > aa 3.0 > > data set 2: > Label Price > bb 2.4 > > > data set 3: > Label Price > cc 2.4 > cc 1.5 > > I wonder what would would be the most straightforward > way of doing this? I was thinking about using > proc freq to get the unique values of Label, then > looping through each value, and subsetting the original > data set according to it. However, I have not been > able to figure out how to perform a loop for anything > other than an array. Any help will be greatly appreciated. > > -Yu

Since you are a self proclaimed newbie, take pause. Typically, breaking a data set into parts is unnecessary.

A BY statement causes SAS to perform its processing per groups of rows of a table. You may only need to SORT the data and the REPORT it!

proc sort data=following ; BY Label; run;

filename report temp; ods html file=report style=sasweb;

proc print data=following; BY Label; run;

ods html close; -- Richard A. DeVenezia http://www.devenezia.com/


Back to: Top of message | Previous page | Main SAS-L page