LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (February 2011, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 21 Feb 2011 16:27:40 -0500
Reply-To:   Rasesh Patel <rasesh.h.patel@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Rasesh Patel <rasesh.h.patel@GMAIL.COM>
Subject:   Re: summary transposition problem
Comments:   To: Arthur Tabachneck <art297@rogers.com>
In-Reply-To:   <201102212052.p1LKpDoq030769@waikiki.cc.uga.edu>
Content-Type:   text/plain; charset=windows-1252

Here is the program.

*

data* d1;

infile datalines;

input id gender $ eyecolor $;

datalines;

1 M Blue

2 F Green

3 M Gray

4 F Blue

; *

RUN*; *

proc* *sort* data=d1;

by gender eyecolor; *

run*; *

proc* *transpose* data=d1

out=d2 (rename=(col1=varcategory _NAME_=Varname));

var eyecolor gender ;

by ID NOTSORTED ;

*

run*;

*

proc* *summary* data=d2 print N noobs;

class varcategory varname;

var id;

OUTPUT OUT=TEST1;

*run*;

On Mon, Feb 21, 2011 at 3:52 PM, Arthur Tabachneck <art297@rogers.com>wrote:

> Evan, > > You could always do it in a datastep using coalescec and arrays. E.g.: > > data want (keep=var: sum:); > set have; > array values(2) $ Gender Eyecolor; > array vnames(2) $; > do i=1 to 2; > if missing(values(i)) then call missing(vnames(i)); > else vnames(i)=vname(values(i)); > end; > varcategory=coalescec(of values(*)); > varname=coalescec(of vnames(*)); > run; > > HTH, > Art > -------- > On Mon, 21 Feb 2011 14:10:38 -0500, Evan Davies <esdav2@WM.EDU> wrote: > > >Letís say I have a data set like this: > > > >Id gender eyecolor > >1 M Blue > >2 F Green > >3 M Gray > >4 F Blue > > > >And want to get this: > > > >Varname varcategory summaryN > >Gender M 2 > >Gender F 2 > >Eyecolor Blue 2 > >Eyecolor Green 1 > >Eyecolor Gray 1 > > > >How would I go about it? > > > >I can use proc tab or proc summary to get this: > > > >Gender Eyecolor summaryN > >M . 2 > >F . 2 > >. Blue 2 > >. Green 1 > >. Gray 1 > > > >Which is only halfway. > > > >I can use a coalesce function to get: > > > >Varname summaryN > >M 2 > >F 2 > >Blue 2 > >Green 1 > >Gray 1 > > > >But that doesnít identify the variable that the values came from. > > > >Key point: I donít want to have to hard code gender, eyecolor, etc into a > >process Ė I need to do this to multiple datasets with different variables, > >and want the categories to define themselves generically, as > variable_name, > >variable_category, and var_summaryN. >


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