| Date: | Fri, 19 Dec 2008 18:11:22 +0000 |
| Reply-To: | karma <dorjetarap@GOOGLEMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | karma <dorjetarap@GOOGLEMAIL.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=ISO-8859-1 |
Here's another way to do it using arrays that preserves the order of
your columns - probably overkill though :s
data have;
input Survey Species$ Average;
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
;run;
proc sql ;
select cats('Survey',survey,'_Avg') as array_list
into: array_list separated by ' '
from (select distinct survey from have)
order by array_list;
quit;
%put &array_list;
data want(drop=survey average);
retain Species;
array arr_survey[*] &array_list;
do until(last.species);
set have;
by species;
arr_survey[survey]=average;
end;
run;
proc print;run;
2008/12/19 <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
>
|