|
Here is one way- assuming you don't know how many sources that you have, first split the data set, then transpose the sources, then merge them back together again. You probably also want to check first that your other variables are identical on the different rows with the same ID, I'm creating a data set "duplicates" that checks to see if the select distinct on the other variables produces only 1 row for each id.
-Mary
data set1;
infile cards;
input id source $ var1 var2 var3;
cards;
1 V 1 2 3
1 S 1 2 3
2 V 10 11 12
3 V 20 21 22
3 S 20 21 22
3 R 20 21 22
;
proc sql;
create table sources as
select id, source
from set1;
create table vars as
select distinct id, var1, var2, var3
from set1;
run;
quit;
proc sql;
create table duplicates as
select sample_name
from vars
where sample_name in(
select sample_name
from vars
group by sample_name
having count(sample_name) >=2)
order by sample_name;
quit;
run;
proc transpose data=sources out=sources_transposed;
var source;
by id;
run;
data final;
merge sources_transposed vars;
by id;
drop _name_;
run;
----- Original Message -----
From: Erica
To: SAS-L@LISTSERV.UGA.EDU
Sent: Wednesday, April 30, 2008 12:12 PM
Subject: Turn obs into vars
Hello all,
I have a SAS dataset that looks like this:
ID Source ...10 Other Vars...
1 V
1 S
2 V
3 V
3 S
3 R
I want:
ID Source1 Source2 Source3 ...10 Other Vars...
1 V S
2 V
3 V S R
Any help would be greatly appreciated!
|