Date: Tue, 8 Jan 2002 05:46:26 GMT
Reply-To: Huck <huck@SKIPTHISFINN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Huck <huck@SKIPTHISFINN.COM>
Organization: AT&T Worldnet
Subject: Re: array vs. transpose
this is the type of solution i would have gone for, first make it long and skinny,
then make it short and fat agin the way you want it.
its very extensable to me, and easy to think of and debug.
i suggested such a solution because you started at a low number of variables,
and seemed to jump quickly, what if the next time you needed to do 20?
the macro/array solution gets cumbersome. Also from what i saw, i realize
that i expect your data to be square, you wanted to go from a 4x4 to a 6x6, or 8x8,
with this more detailed description of your problem its easy to catch that error.
but yet i showed you how to do what you asked, in macro... why?
cause this problem is one of the many many many that have no RIGHT solution,
and even few BETTER solutions, you pick the one you know of and that works ok.
and while it was fair for me to suggest the transpose solution as being better,
it was unfair to feel it was the best or only. and the actual code you were asking for was too
simple. yea at 20x20 its a bear, but if you did stop at 6x6 it wouldnt be too bad.....
that is the power of sas-l too, you learn alternative solutions, ones that excell in one way or
another, and while may not be for everyday use, they may be usefull in special conditions.
so dont come here looking for THE ANSWER, when you ask here you will get a collection
of varied opinions, and its up to you to pick the one that is best FOR YOU. Sometimes if
your question is "good enuf" you will get an answer from one of the "experts" here,
and it may be too complicated to fit your problem well,
and an simple answer from a "newbie" turns out to fit your problem better.
So use the one that fits.
i like transpose, so i use it a lot, yet i couldnt just type out all the code you needed.
i could type out code close to what you wanted to do (you had to unsquare what i wrote
by changeing an &nvar reverence to a hard 4 in some places), so i did that too,
was either method better, only you could tell,
ok the "betterness" of my two routines,
neither of which actualy does work exactly like she wanted,
is not being debated,
its the principle.... uhuh its the principle ..... come on its the principle .....
ps , Nat ya got to change sequence back to 1 sometime here ....
if lag(ptid) ne ptid then sequence=0 ; ???
On 7 Jan 02 20:48:38 GMT, Nathaniel_Wooding@DOM.COM (Nathaniel Wooding) wrote:
>I'm not sure that you need to use a macro or an array in this particular
>case. The solution below should work for any number of variables (with the
>caveat that eventually you could give your machine too much work to
>perform). Please note that I specified the variables as a list in the proc
>transpose variables statement. If you only had character variables, you
>could write var _character_ instead of var _ae -- prog ; Note that -- is
>This solution is open-ended in that you it will handle various numbers of
>variables and characters, especially if you can use the _character_
>version. Arrays certainly will work. I prefer the transpose solution if the
>data set is not too large (and this will depend on your computer) and will
>run in a suitable length of time. To me, the code is much simpler.
>However, if the data set becomes so large that the computer time becomes a
>burden, then it would be worthwhile to look at arrays.
>Here is a Proc Transpose solution:
>PTID AE $8. SEVERE $10. MEDRLTD $3. prog $8.;* i added another var;
>500 cough moderate no good
>500 TIA severe no fair
>500 MI severe no poor
>proc transpose out=a;by ptid sequence;var ae -- prog;* now we can add the
>numbers to the variables;
>proc transpose out=a (drop=_name_);var col1;id _name_;by ptid;
> Mahadocon To: SAS-L@LISTSERV.UGA.EDU
> <kmahadocon@PC cc:
> YC.COM> Subject: array vs. transpose
> Sent by:
> 01/07/02 12:14
> Please respond
> to Kristi
>Some time ago, I posted a message about help with proc transpose, and
>received an answer using arrays that worked quite well for my example.
>Last week I posted a message about the same problem, but a larger version,
>and was advised to use proc transpose instead of arrays. I am now quite
>confused as to the best way to achieve the results I need. I am going to
>post my original problem and any suggestions on the best solution would be
>GREATLY appreciated. I am using V6.12 on NT.
>I have several datasets such as (simplified version) below:
>PTID AE SEVERE MEDRLTD ........ could be up to 17 variables;
>500 cough moderate no
>500 TIA severe no
>500 MI severe no
>I need to get them into the form:
>PTID AE1 SEVERE1 MEDRLTD1 .... AE2 SEVERE2 MEDRLTD2
>500 cough moderate no TIA severe no
>The datasets could have 4-17 variables and 2-10 observations per patient
>and I need to get them back into the one observation per patient format.
>Obviously I would like a solution that I could put into a macro and call
>once for each dataset instead of having to write code for each dataset. Am
>I expecting too much? HELP!
and why have i posted more in the last week than durring all of the 90's?
ill go back into my corner again .....