Date: Fri, 16 Sep 2011 11:43:52 -0400
Reply-To: bbser 2009 <bbser2009@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: bbser 2009 <bbser2009@GMAIL.COM>
Subject: Re: No one here to help me in coding
In-Reply-To: <201109161325.p8GAkm8O026064@waikiki.cc.uga.edu>
Content-Type: text/plain; charset="iso-8859-1"
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
>
>