+ Reply to Thread
Results 1 to 2 of 2

Thread: Array Question

  1. #1
    Points: 3,892, Level: 39
    Level completed: 62%, Points required for next Level: 58

    Posts
    302
    Thanks
    16
    Thanked 15 Times in 15 Posts

    Array Question



    Basically, I wanted to know how to change multiple lines for one subject to just one line per subject. For example,

    rather than having data as:

    ID X Time
    01 1 1
    01 3 2
    01 5 3
    02 2 1
    02 4 2
    03 6 1
    ....
    ....

    I wanted it to look like this:

    ID X1 X2 X3 X4 ..............X8
    01 1 3 5 .
    02 2 4 . .
    03 6 . . .
    ....
    ....

    I needed to use a retain statement to do this and found that I the code would be as follows:

    data score1;
    array Y[8] X1-X8;
    retain X1-X8;
    set score;
    by ID;
    if first.ID then do i=1 to 7;
    Y[i]=.;
    end;
    Y[TIME]=X;
    if last.ID then output;
    keep ID X1-X8;
    run;
    Last edited by lancearmstrong1313; 03-17-2012 at 10:29 AM.

  2. #2
    Point Mass at Zero
    Points: 5,855, Level: 49
    Level completed: 53%, Points required for next Level: 95
    ledzep's Avatar
    Location
    Berks,UK
    Posts
    635
    Thanks
    169
    Thanked 130 Times in 128 Posts

    Re: Array Question


    Please don't delete the question, even though you've figured out the answer. I would strongly encourage you to post the solution if you've solved it yourself. There could always be someone out there with exactly the same question as you had.
    Oh Thou Perelman! Poincare's was for you and Riemann's is for me.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats