Hi everyone, anyone can help me with this?;
I I have got the dataset have, and I want to convert it in a dataset want , please find below *;
data have;
input subjid siteid param $ response $;
datalines;
1 100 u a
1 100 v a
1 100 w a
1 100 u b
1 100 v b
1 100 w b
2 200 u a
2 200 v a
2 200 w a
3 300 u a
3 300 v a
3 300 w a
3 300 u b
3 300 v b
3 300 w b
;
run;
I would like this kind of dataset want, with this structure *:
response a response b
site 100 u v w
u
v
w
site 200 u
v
w
site 300 u
v
w
Thanks in advance,
V.
data want;
do until (last.siteid);
set have;
by siteid;
length site response_a response_b $20.;
site=catx(' ','site',siteid);
if response='b' then response_b=catx(' ',response_b,param); else response_b=response_b;
end;
do _n_=1 by 1 until (last.siteid);
set have;
by siteid;
if _n_>1 then call missing (site,response_b);
if response='a' then response_a=param; else response_a='';
if not missing(response_a) then output;
end;
keep site response_:;
run;
Haikuo
Can you provide your want structure as a data step as well. It's hard to visualize how you want it. Also, is this to be displayed or in a dataset? What should the blanks be?
It an't pretty, but seems does what you want.
data have;
input subjid siteid param $ response $;
datalines;
1 100 u a
1 100 v a
1 100 w a
1 100 u b
1 100 v b
1 100 w b
2 200 u a
2 200 v a
2 200 w a
3 300 u a
3 300 v a
3 300 w a
3 300 u b
3 300 v b
3 300 w b
;
run;
data want;
do until (last.siteid);
set have;
by siteid;
length site response_a response_b $20.;
site=catx(' ','site',siteid);
response_b=ifc(response='b',catx(' ',response_b,param), response_b);
end;
do _n_=1 by 1 until (last.siteid);
set have;
by siteid;
if _n_>1 then call missing (site,response_b);
response_a=ifc(response='a',param,'');
if not missing(response_a) then output;
end;
keep site response_:;
run;
Haikuo
Hi Haikuo,
please , could you supply the function ifc for another line of code to see if you generate the right dataset?,
because IFC does not work in my 9.0 SAS version.
Thanks,
Jose.
data want;
do until (last.siteid);
set have;
by siteid;
length site response_a response_b $20.;
site=catx(' ','site',siteid);
if response='b' then response_b=catx(' ',response_b,param); else response_b=response_b;
end;
do _n_=1 by 1 until (last.siteid);
set have;
by siteid;
if _n_>1 then call missing (site,response_b);
if response='a' then response_a=param; else response_a='';
if not missing(response_a) then output;
end;
keep site response_:;
run;
Haikuo
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.