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 (December 2008, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 19 Dec 2008 12:56:41 -0500
Reply-To:   Nathaniel.Wooding@DOM.COM
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Nat Wooding <Nathaniel.Wooding@DOM.COM>
Subject:   Re: Creating new variables in a new dataset
In-Reply-To:   <b41c47f5-dcb0-4aa1-92a0-7b4dccfe7812@f40g2000pri.googlegroups.com>
Content-Type:   text/plain; charset="US-ASCII"

Mike

You could do this with arrays but I, for one, prefer Proc Transpose.

Do note that the order of the new variables will be determined by the order that they are created. Hence, since survey 2 first appears after surveys 3 and 4, it follows them in the program data vector. If this bothers you, you can add a set of dummy values that will be in survey order and which would appear before any of the other species in your initial file; data mike; input Survey Species $7. Average ; _name_ = compress( 'Survey' || Put( Survey , $1. ) || '_avg' ); * _name_ is the default id variable; cards; 1 Crab 1.5 3 Crab 2.8 4 Crab 2.1 2 Fish 3.2 5 Fish 2.5 2 Seaweed 1.2 4 Seaweed .8 5 Seaweed .6 Proc transpose out = table (drop = _name_ ); var average; by Species; run; proc print;run;

Nat Wooding Environmental Specialist III Dominion, Environmental Biology 4111 Castlewood Rd Richmond, VA 23234 Phone:804-271-5313, Fax: 804-271-2977

mholmes71@HOTMAIL .COM Sent by: "SAS(r) To Discussion" SAS-L@LISTSERV.UGA.EDU <SAS-L@LISTSERV.U cc GA.EDU> Subject Creating new variables in a new 12/19/2008 12:30 dataset PM

Please respond to mholmes71@HOTMAIL .COM

Hi all, I have a data set with three variables: Survey, Species, average.

Survey can be from 1-5. I want to create 5 columns corresponding to the averages from the 5 surveys.

For instance, I might have the following

Survey Species Average 1 Crab 1.5 3 Crab 2.8 4 Crab 2.1 2 Fish 3.2 5 Fish 2.5 2 Seaweed 1.2 4 Seaweed .8 5 Seaweed .6

And I want my new dataset to look like this

Species Survey1_Avg Survey2_Avg Survey3_Avg Survey4_Avg Survey5_Avg Crab 1.5 . 2.8 2.1 . Fish 3.2 . . . 2.5 Seaweed . 1.2 . .8 .6

Any thoughts on how to accomplish this? I assume I would need to make a new data set. Thanks in advance.

Mike

CONFIDENTIALITY NOTICE: This electronic message contains information which may be legally confidential and/or privileged and does not in any case represent a firm ENERGY COMMODITY bid or offer relating thereto which binds the sender without an additional express written confirmation to that effect. The information is intended solely for the individual or entity named above and access by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, distribution, or use of the contents of this information is prohibited and may be unlawful. If you have received this electronic transmission in error, please reply immediately to the sender that you have received the message in error, and delete it. Thank you.


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