|
|
how to use variable value as variable in the same dataset
proc format;
value parm 74='var1'
75='var2'
76='var3';
data test;
var1=1;
var2=2;
var3=3;
x=74;
y=put(x,parm.);
z=Y;
run;
i want z=1 that means y is var1 but how can i assign the value of y
as a variable in the same dataset to another variable
Thanks in advance
|
|
0
|
|
|
|
Reply
|
addanki007 (19)
|
3/13/2010 5:16:53 AM |
|
On Mar 13, 12:16=A0am, sasguy <addanki...@gmail.com> wrote:
> proc format;
> =A0value parm 74=3D'var1'
> =A0 =A0 =A0 =A0 =A0 =A0 75=3D'var2'
> 76=3D'var3';
>
> data test;
> var1=3D1;
> var2=3D2;
> var3=3D3;
> x=3D74;
> y=3Dput(x,parm.);
> z=3DY;
>
> run;
> i want z=3D1 that means y is var1 =A0but how can i assign the value of y
> as a variable in the same dataset to another variable
> Thanks in advance
One way is to use ARRAY statement and use the value of variable as the
index.
Example:
array v var1-var3;
var1=3D101;
x=3D1;
y=3Dv(x);
--> y=3D101
With the numbers in your example you could just subtract 73 from X to
get the index.
For a more complicated example you could use your format trick to
convert the actual values to the index needed for that variable.
- Tom
|
|
0
|
|
|
|
Reply
|
tom.abernathy (199)
|
3/13/2010 5:06:21 PM
|
|
On Mar 13, 9:06=A0am, Tom Abernathy <tom.aberna...@gmail.com> wrote:
> On Mar 13, 12:16=A0am, sasguy <addanki...@gmail.com> wrote:
>
>
>
>
>
> > proc format;
> > =A0value parm 74=3D'var1'
> > =A0 =A0 =A0 =A0 =A0 =A0 75=3D'var2'
> > 76=3D'var3';
>
> > data test;
> > var1=3D1;
> > var2=3D2;
> > var3=3D3;
> > x=3D74;
> > y=3Dput(x,parm.);
> > z=3DY;
>
> > run;
> > i want z=3D1 that means y is var1 =A0but how can i assign the value of =
y
> > as a variable in the same dataset to another variable
> > Thanks in advance
>
> One way is to use ARRAY statement and use the value of variable as the
> index.
> Example:
> =A0 array v var1-var3;
> =A0 var1=3D101;
> =A0 x=3D1;
> =A0 y=3Dv(x);
> --> y=3D101
>
> With the numbers in your example you could just subtract 73 from X to
> get the index.
> For a more complicated example you could use your format trick to
> convert the actual values to the index needed for that variable.
>
> - Tom- Hide quoted text -
>
> - Show quoted text -
Hi All,
I think you should try vvaluex, just change z=3Dy to z-=3Dvvaluex(y);
Toby Dunn had a brilliant use of vvaluex whith ods output and proc
freq tables _all_ a while ago, his solution reduced my 30 lines of
code to about three lines.
Symrefs can be very powerfull.
28745 data test;
28746 var1=3D1;
28747 var2=3D2;
28748 var3=3D3;
28749 x=3D74;
28750 y=3Dput(x,parm.);
28751 z=3DY;
28752 q=3Dvvaluex(y);
28753 put q=3D;
28754 run;
Q=3D1
NOTE: The data set WORK.TEST has 1 ob
NOTE: DATA statement used (Total proc
real time 0.00 second
cpu time 0.01 second
|
|
0
|
|
|
|
Reply
|
xlr82sas (391)
|
3/13/2010 10:20:39 PM
|
|
|
2 Replies
275 Views
(page loaded in 0.071 seconds)
|
|
|
|
|
|
|
|
|