BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
michtka
Fluorite | Level 6

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

View solution in original post

4 REPLIES 4
Reeza
Super User

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?

Haikuo
Onyx | Level 15

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

michtka
Fluorite | Level 6

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.

Haikuo
Onyx | Level 15

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 637 views
  • 0 likes
  • 3 in conversation