From: sasguy on 13 Mar 2010 00:16 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
From: Tom Abernathy on 13 Mar 2010 12:06 On Mar 13, 12:16 am, sasguy <addanki...(a)gmail.com> wrote: > 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 One way is to use ARRAY statement and use the value of variable as the index. Example: array v var1-var3; var1=101; x=1; y=v(x); --> y=101 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
From: xlr82sas on 13 Mar 2010 17:20 On Mar 13, 9:06 am, Tom Abernathy <tom.aberna...(a)gmail.com> wrote: > On Mar 13, 12:16 am, sasguy <addanki...(a)gmail.com> wrote: > > > > > > > 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 > > One way is to use ARRAY statement and use the value of variable as the > index. > Example: > array v var1-var3; > var1=101; > x=1; > y=v(x); > --> y=101 > > 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=y to z-=vvaluex(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=1; 28747 var2=2; 28748 var3=3; 28749 x=74; 28750 y=put(x,parm.); 28751 z=Y; 28752 q=vvaluex(y); 28753 put q=; 28754 run; Q=1 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
|
Pages: 1 Prev: adding +6 to age Next: How to condense multiple observations |