From: Bill McKirgan on
I have data that I can read but have trouble transposing from long to
wide because of duplication in the key variables: ID and EVENT.

The REPEAT variable included with these data is incorrect and I want
to have it increase by one for every group of questions.

To keep it simple I excluded the result values coded for each
question.

I'm hoping someone can help me go from what I got to what is 'wanted'
as I outlined it below.

data got;
input id $ event $ q_order $ repeat $ question $11. ;
put id event q_order repeat question ;
datalines;
00z3 207 1 0 site_id
00z3 207 2 0 comp_id
00z3 207 3 0 eval_date
00z3 207 4 0 study_id
00z3 207 5 0 eval_time
00z3 207 6 0 doc_id_text
00z3 207 7 0 q01
00z3 207 8 0 q02
00z3 207 1 0 site_id
00z3 207 2 0 comp_id
00z3 207 3 0 eval_date
00z3 207 4 0 study_id
00z3 207 5 0 eval_time
00z3 207 6 0 doc_id_text
00z3 207 7 0 q01
00z3 207 8 0 q02
00z3 207 1 0 site_id
00z3 207 2 0 comp_id
00z3 207 3 0 eval_date
00z3 207 4 0 study_id
00z3 207 5 0 eval_time
00z3 207 6 0 doc_id_text
00z3 207 7 0 q01
00z3 207 8 0 q02
;
run;

data WANTED;
input id $ event $ q_order $ repeat $ question $11. ;
put id event q_order REPEAT question ;
datalines;
00z3 207 1 0 site_id
00z3 207 2 0 comp_id
00z3 207 3 0 eval_date
00z3 207 4 0 study_id
00z3 207 5 0 eval_time
00z3 207 6 0 doc_id_text
00z3 207 7 0 q01
00z3 207 8 0 q02
00z3 207 1 1 site_id
00z3 207 2 1 comp_id
00z3 207 3 1 eval_date
00z3 207 4 1 study_id
00z3 207 5 1 eval_time
00z3 207 6 1 doc_id_text
00z3 207 7 1 q01
00z3 207 8 1 q02
00z3 207 1 2 site_id
00z3 207 2 2 comp_id
00z3 207 3 2 eval_date
00z3 207 4 2 study_id
00z3 207 5 2 eval_time
00z3 207 6 2 doc_id_text
00z3 207 7 2 q01
00z3 207 8 2 q02
;
run;





From: PJ on
I hope codes below would help.

data want(drop=last);
set got(drop=repeat);
retain last;
retain repeat 0;
by id event;
if first.event then last = q_order;
if q_order <= last and _n_ ne 1 then repeat + 1;
run;

BR,
PJ
From: Bill McKirgan on
On Jun 9, 1:20 pm, PJ <luxuem...(a)yahoo.com> wrote:
> I hope codes below would help.
>
> data want(drop=last);
>   set got(drop=repeat);
>   retain last;
>   retain repeat 0;
>   by id event;
>   if first.event then last = q_order;
>   if q_order <= last and _n_ ne 1 then repeat + 1;
> run;
>
> BR,
> PJ





PJ,

The example you provided was very helpful.

Thank you!

--Bill McKirgan