Date: Thu, 11 Aug 2011 02:24:31 -0400
Reply-To: Søren Lassen <s.lassen@POST.TELE.DK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Søren Lassen <s.lassen@POST.TELE.DK>
Subject: Re: concatinating non missing variables only!
Content-Type: text/plain; charset=ISO-8859-1
Shyamprasad,
This is one of the cases where you should use CALL CATX rather than
the CATX function, as you are repeatedly adding to the same variable.
And then, this example lends itself very well to the all but forgotten
DO OVER construct:
data want;
set have;
array vars x--z;
length newvar $8;
do over vars;
if not missing(vars) then
call catx(';',newvar,upcase(vname(vars)));
end;
run;
(DO OVER creates a hidden variable _I_, which is used to iterate
through the array and then dropped - it simplifies coding somewhat,
but should only be used in simple cases)
Regards,
Søren
On Wed, 10 Aug 2011 13:48:13 -0400, shyamprasad samisetti
<shyam.cbz@GMAIL.COM> wrote:
>Dear sas users,
>
>I am looking for an efficient approach for the below task. The way I did is
>by coding concatenation for all possible combination of non missing
>variables. This lead to me a question if many variables are present which
>would lead to many combinations which would not be an efficient way by
>writing several if-then statemtents.
>
>My goal is to create a variable newvar based on the below three variables
x,
>y, z.
>if xvar is checked use 'X'
>if yvar is checked use 'Y'
>if zvar is checked use 'Z'
>X;Y;Z
>
>Newvar looks like this.
>xvar yvar zvar NEWVAR
>xx xx X;Y
>xx xx X;Z
> xx Y
>xx xx X;Y
>xx xx xx X;Y;Z
> xx xx Y;Z
> xx Z
>xx X
>
>Thanks
>Shyam.
|