From: Al on

All:

This is the data i have ..


pat vis res
1 1 12
1 1.1 13
1 1.2 12
1 2 11
2 1 09
2 2 14
2 3 11
3 1 10
3 2 11
3 3 1.1
3 4 10



The desired data structure is one record per pat.. i able to do it
using proc transpose
but i want to know how this is can be done using arrays..
Any suggestions ..

Thanks in advance
Al
From: Patrick on
Why code some data step when Proc Transpose does it so easily. That's
the real power of SAS.

In order to use arrays you would have to pass the data set twice AND
to sort the data set previously.
The first pass through the data (sorted) is to to find the biggest
numer of observations per by group (pat) which then is the number of
array elements, the second time to assign the values to the array
elements - and then: if last.pat then output;
From: Al on
On May 11, 6:52 am, Patrick <patrick.mat...(a)gmx.ch> wrote:
> Why code some data step when Proc Transpose does it so easily. That's
> the real power of SAS.
>
> In order to use arrays you would have to pass the data set twice AND
> to sort the data set previously.
> The first pass through the data (sorted) is to to find the biggest
> numer of observations per by group (pat) which then is the number of
> array elements, the second time to assign the values to the array
> elements - and then: if last.pat then output;

Just want to know how the datastep works for this kind of scenario

Thanks
al
From: Al on
On May 11, 9:05 am, Al <ali6...(a)gmail.com> wrote:
> On May 11, 6:52 am, Patrick <patrick.mat...(a)gmx.ch> wrote:
>
> > Why code some data step when Proc Transpose does it so easily. That's
> > the real power of SAS.
>
> > In order to use arrays you would have to pass the data set twice AND
> > to sort the data set previously.
> > The first pass through the data (sorted) is to to find the biggest
> > numer of observations per by group (pat) which then is the number of
> > array elements, the second time to assign the values to the array
> > elements - and then: if last.pat then output;
>
> Just want to know how the datastep works for this kind of scenario
>
> Thanks
> al

Can any one help me with code for data step using Array for the above
scenario

Thanks in Advance
From: Reeza on
On May 11, 8:32 am, Al <ali6...(a)gmail.com> wrote:
> On May 11, 9:05 am, Al <ali6...(a)gmail.com> wrote:
>
>
>
>
>
> > On May 11, 6:52 am, Patrick <patrick.mat...(a)gmx.ch> wrote:
>
> > > Why code some data step when Proc Transpose does it so easily. That's
> > > the real power of SAS.
>
> > > In order to use arrays you would have to pass the data set twice AND
> > > to sort the data set previously.
> > > The first pass through the data (sorted) is to to find the biggest
> > > numer of observations per by group (pat) which then is the number of
> > > array elements, the second time to assign the values to the array
> > > elements - and then: if last.pat then output;
>
> > Just want to know how the datastep works for this kind of scenario
>
> > Thanks
> > al
>
> Can any one help me with code for data step using Array  for the above
> scenario
>
> Thanks in Advance- Hide quoted text -
>
> - Show quoted text -

As stated above, you need to do one pass through the data and figure
out how many records per patient, the maximum size of the array.
Array sizes need to be declared at the beginning and cannot grow (last
time I checked) so this method becomes fairly inefficient due to this
restrictions.

Else sort the data by patient, vist and use first/last with an array.
Some untested code below:

proc sort data=have;
by pat visit;

data want;
set have;
by pat;
array pat_visits{30}; (i'm assuming 30 is the maximum, you'd have to
find out.
retain index=1; *what record are you dealing with for the patient;

pat_visits[index]=res; *assigns value to array;

if pat.last then do; *if last record for patient output and reset
index;
index=0;
output;
end;

index=index+1; *increment index for next row;
run;