Date: Fri, 16 Sep 2011 11:35:01 -0500
Reply-To: "Data _null_;" <iebupdte@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Data _null_;" <iebupdte@GMAIL.COM>
Subject: Re: No one here to help me in coding
In-Reply-To: <201109161614.p8GFStxk026064@waikiki.cc.uga.edu>
Content-Type: text/plain; charset=UTF-8
You could create a list of var names of the variables in the array and
use WHICHC. I expect it would be slightly faster than searching.
A method I'm liking these days is to create a hash table as a look up
(by name) for the index to array(s). Its a bit fiddly but once you
get it coded it is pretty easy to use.
On Fri, Sep 16, 2011 at 11:14 AM, Tom Abernathy <tom.abernathy@gmail.com> wrote:
> You could brute force it by looping over array and using VNAME to find the
> index for the variable name that matches.
> (untested code)
>
> i1=0;
> do i=1 to dim(ww) while (i1=0);
> Â if var1 = vname(ww(i)) then i1=i;
> end;
>
>
>
> On Fri, 16 Sep 2011 11:43:52 -0400, bbser 2009 <bbser2009@GMAIL.COM> wrote:
>
>>Tom, what if those WWs becoming u,v, w, x, y?
>>Is there a neat way to do this without using vvaluex()?
>>Thanks.
>>
>>Regards, Max
>>(Maaxx)
>>
>>-----Original Message-----
>>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Tom
>>Abernathy
>>Sent: September-16-11 9:25 AM
>>To: SAS-L@LISTSERV.UGA.EDU
>>Subject: Re: [SAS-L] No one here to help me in coding
>>
>>Vishali -
>>
>> Â It looks like your problem is that you want to use the value of variable
>>as a reference to the another variable in the same data step. This is a
>>little hard to do in SAS. Â I can see two methods.
>>
>> Â One you could use the VVALUEX function to return the value of the
>>variable. Â So if VAR1='WW1' you could use VVALUEX(var1) to return the value
>>of WW1. The problem with this is that it returns the formatted value as a
>>CHARACTER string. Â This might case lose of precision, notes to the log or
>>other issues.
>> Â s= vvaluex(var1) - vvaluex(var2) ;
>>
>> Â If you can insure that your variables are named with nice numeric
> suffixes
>>as in your example then you could parse out the suffix and use it as the
>>index into an array.
>>
>>data have ;
>> input var1 $ var2 $ ww1-ww5 ;
>>cards;
>>WW1 WW2 1 3 1 2 4
>>WW2 WW1 3 3 4 3 4
>>WW3 WW4 3 2 3 3 4
>>WW4 WW3 4 2 4 3 5
>>WW5 WW2 4 2 2 4 5
>>run;
>>
>>data want ;
>> Â set have ;
>> Â array ww ww1-ww5 ;
>> Â i1 = input(substr(var1,3),best.);
>> Â i2 = input(substr(var2,3),best.);
>> Â s = ww(i1) - ww(i2) ;
>>run;
>>
>> Â PS: If you could switch to using plain text for posting your email will
> be
>>easier to read via the SAS-L page at University of Georgia.
>>
>>On Fri, 16 Sep 2011 17:37:16 +0530, Vishali Rajiv <vishalirajiv@YAHOO.COM>
>>wrote:
>>
>>>
>>
>>
>>From: Vishali Rajiv <vishalirajiv@YAHOO.COM>
>>To: SAS-L@LISTSERV.UGA.EDU
>>Sent: Friday, 16 September 2011 10:54 AM
>>Subject: substraction code
>>
>>can you help me wity the code for substraction ,I wanted to substract the
>>below BOLDED values,your help is appreciated.
>>
>>
>>�
>>>�
>>>VAR1��������� VAR2���� WW1�� WW2� WW3��
>>WW4� WW5� substraction
>>>--------------------------------------------------------------------------
> -
>>------
>>>WW1���������� WW2������
>>1���������� 3���������
>>1�������� 2��������
>>�4�������������.
>>>WW2���������� WW1������
>>3���������� 3��������
>>�4�������� 3��������
>>�4�������������.
>>>WW3���������� WW4������
>>3���������� 2��������
>>�3�������� 3��������
>>�4�������������.
>>>WW4���������� WW3������
>>4���������� 2��������
>>�4������� �3��������
>>�5������������ .
>>>WW5���������� WW2������
>>4���������� 2��������
>>�2�������� 4��������
>>�5������������ .
>>>
>>>�
>>>�
>>>FORMULA
>>>-----------
>>>WW1-WW2� 1-3 =-2
>>>WW2-WW1� 3-3 =0
>>>WW3-WW4� 3-3 =0
>>>WW4-WW3� 3-4 =-1
>>>WW5-WW2� 5-2=-3
>>>�
>>>FINAL OUTPT I WANT LIKE BELOW FROMAT
>>>--------------------------------------------------------
>>>VAR1��������� VAR2���� WW1�� WW2� WW3��
>>WW4� WW5� substraction
>>>--------------------------------------------------------------------------
> -
>>------
>>>WW1���������� WW2������
>>1���������� 3���������
>>1�������� 2��������
>>�4�������������2
>>>WW2���������� WW1������
>>3���������� 3��������
>>�4�������� 3��������
>>�4�������������0
>>>WW3���������� WW4������
>>3���������� 2��������
>>�3�������� 3��������
>>�4�������������0
>>>WW4���������� WW3������
>>4���������� 2��������
>>�4������� �3��������
>>�5������������ 1
>>>WW5���������� WW2������
>>4���������� 2��������
>>�2�������� 4��������
>>�5������������ 3
>>>
>>>
>
|