Date: Fri, 17 Aug 2001 15:52:24 -0500 aldi@wubios.wustl.edu "SAS(r) Discussion" Aldi Kraja Washington University Re: Counting Unique Occurrences of a Variable's Value text/plain; charset=us-ascii

Hi William, HTH, Aldi

Output: ====== Obs var1 var2 var3 flag1 flag2

1 1 2 1 2 1 2 1 1 1 3 0

Partial program: ============= data a2 (drop=j); set a1; array variable{*} var1-var3; flag1=0; flag2=0; do j=1 to dim(variable); if variable[j]=1 then do; flag1=flag1+1; flag2=flag2+0; end; else if variable[j]=2 then do; flag2=flag2+1; flag1=flag1+0; end; end;

run;

William Dudley wrote:

> I have had this problem as well. > Although SQL and Proc versions are helpful > I wonder if there is a way to assign the counts to a varaible. > > In SPSS i can > > Count flag1 = var1 var2 var3 (1). > Count flag2 = var1 var2 var3 (2). > > If I have > id Var1 var2 var3 > 1 1 2 1 > 2 1 1 1 > > I will then get > id Var1 var2 var3 flag1 flag2 > 1 1 2 1 2 1 > 2 1 1 1 3 0 > > The varaible Flag1 will give me the number of times the number one appear in the variable list for each case. > Flag 2 will give the numbero f time 2 apperaed etc. > If there a way to do this in SAS? > > Thanks > Bill > > *********************************************** > * William N. Dudley, PhD > * University of Utah > * College of Nursing > * 10 S 2000 E Front > * Salt Lake City, UT 84122-5880 > *********************************************** > > >>> "Terjeson, Mark" <TerjeMW@DSHS.WA.GOV> 08/17/01 02:05PM >>> > Hi Eric, > > Harry gave you the SQL version. > Here is a PROC version. > > DATA A; > INPUT ID@@; > cards; > 1 1 1 2 2 3 4 4 6 6 > ; > run; > > proc freq data=a; > table id / list missing; > run; > > Hope this is helpful, > Mark Terjeson > Washington State Department of Social and Health Services > Division of Research and Data Analysis (RDA) > mailto:terjemw@dshs.wa.gov > > -----Original Message----- > From: Hanson, Eric A [mailto:Eric.Hanson@CFSAN.FDA.GOV] > Sent: Friday, August 17, 2001 12:31 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Counting Unique Occurrences of a Variable > > Does anyone know of a PROC that will count the number of times a unique > value of a variable appears in a data set? > > For example > > DATA A; > INPUT ID@@; > cards; > 1 1 1 2 2 3 4 4 6 6; > run; > > There are 5 unique values of the variable ID here. This seems almost too > easy, but I have not found a way to do this count with a PROC that does not > create another dataset (like SORT with nodupkey) or using first.id > constructs. > > Thanks > Eric Hanson

--

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