COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### how to use variable value as variable in the same dataset

• Email
• Follow

```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
```
 0

See related articles to this posting

```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

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
>
> 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
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
345 Views

Similar Articles

12/19/2013 9:58:15 PM
page loaded in 31681 ms. (0)

Similar Artilces:

Using formatted variable (format values) as class/group variable
Dear Group, I have a date variable which is formatted to give the week values (weekv5.). Now I want to count another variable by this one. Is there a more efficient way than the one given in the following example? data test; infile datalines; input datum date9. user \$; format datum weekv5.; datalines; 01JAN2006 4452 05JAN2006 4457 07JAN2006 4457 11JAN2006 4392 12JAN2006 4889 14JAN2006 4400 15JAN2006 4490 17JAN2006 4901 ; run; data test; set test; datum_c = put(datum, weekv5.); run; proc sql; select datum_c, count(user) as n from test group by datum_c; quit; The dataset has some 40E+...

DATA step q: variable has name of variable to use for value
Here's a stripped down version of a problem one of my users had. Data set one has the following. var1 var2 var3 var4 indicate1 indicate2 1 2 3 4 var3 var4 5 6 7 8 var1 var2 9 10 11 12 var3 var1 He wanted to create 2 new variables, new1 and new2, whose values are the values of the variables named in indicate1 and indicate2, respectively. That is, in observation 1, indicate1="var3" and the value of var3 is 3, so new1= 3. indicate2="var4" and the value of var4 is 4, so new2= 4. in observation 2, indicate1=&q...

Re: DATA step q: variable has name of variable to use for value #8
> From: Bruce F. Gilsen > Here's a stripped down version of a problem one of my users had. > > Data set one has the following. > > var1 var2 var3 var4 indicate1 indicate2 > 1 2 3 4 var3 var4 > 5 6 7 8 var1 var2 > 9 10 11 12 var3 var1 > > He wanted to create 2 new variables, new1 and new2, whose > values are the values of the variables named in indicate1 and > indicate2, respectively. That is, > > in observation 1, > indicate1="var3" and the value of var3 is 3, so new1= 3....

Re: DATA step q: variable has name of variable to use for value #9
Another approach to this problem would be to use the data set information functions - OPEN and so forth. More work, but in some ways more power in this method. By the way, I fully expect that I will get a bounce message from Ron's email system, as anything I send to him (and to at least one other person at the CDC) seems to fail. Does anyone else have that problem? -- JackHamilton@FirstHealth.com Manager, Technical Development Metrics Department, First Health West Sacramento, California USA >>> "Fehd, Ronald J." <RJF2@CDC.GOV> 11/23/2004 6:05 AM >>>...

Re: DATA step q: variable has name of variable to use for value #5
Bruce, =20 If you have SAS v9.0 or higher you could try using vvalue or vvaluex. =20 Very untested so watch out: =20 =20 data one; set <your dataset>; new1 =3D vvaluex(indicate1); new2 =3D vvaluex(indicate2); run; =20 =20 Should work for you if I am reading the SAS online docs correctly. =20 HTH and wish I could test this but atlast I am at home with no SAS to = try it on till the morning. =20 Toby Dunn ________________________________ From: SAS(r) Discussion on behalf of Bruce F. Gilsen Sent: Mon 11/22/2004 5:22 PM To: SAS-L@LISTSERV.UGA.EDU Subject: DATA step q: variable has name of ...

Dataset : variable with value to added in empty dataset
Hi All, This is the example data a; input ID name \$; datalines; ; data C; set a; if _n_=0; var1="John"; run; My situation is similar to this. I created a table from proc sql, where sql query returns 0 records. After that I want add a variable with value. But it is not working. proc sql; create table a as select * from a; quit; Now table a have 0 observations. data a; set a; var1="Smith"; run; Proc print; returns 0 observations. I want Smith to be added in dataset a. Help please. Any other way also welcome. AA wrote: > Hi All, > This is the example > data a...

create multiple datasets from one dataset by variable values
Hi Now I need to create a dataset var2_x, var2_y , var3_z which contains var1, var2 and var3 only for the corresponding var2 values . dataset X var1 var 2 var3 32 peter 2 23 peter 3 11 peter 1 17 rob 2 45 rob 4 65 rob 6 21 sam 1 24 sam 7 Output has to look like this: dataset1:var2_x var1 var 2 var3 32 peter 2 23 peter 3 11 peter 1 dataset2:Var2_y 17 rob 2 45 rob 4 dataset3:Var2_z 21 sam 1 24 sam 7 The dataset has 30000 rows .Browsing...

Creating a new variable my using updated values values
Hi, I am looking to create a new variable by merging two existing variables. I have a variable that will always have a number (GB), and another variable that periodically gets updated (JC). I want to create a new variable (JL) that always has the updated variable (JC), unless there is no value, in which case it takes the value of the un-updated value (GB). For example: GB JC JL 23 . (missing) 23 24 32 32 25 . 25 26 42 ...

using variable-value
Hi In php I can assign a value to a variable and use this varaible to access a property in some object: \$var = 'property'; \$object->{\$var} This will transelate to \$object->property... Is this possible in Python? # Prints help on methods in Canvas-instance for method in dir(self.canvas): print method print help(self.canvas.method) gives me " AttributeError: Canvas instance has no attribute 'method' "... regards tores Tor Erik S�nvisen wrote: > Hi > > In php I can assign a value to a variable and use this varaible to access a > pro...

Re: Divide datasets into sub-datasets based on Variable Value #2
Ahh, now I've read it more closely: the number of 3 values is NOT fixed! You don't know it! Ok, that seems to be more complicate. data a; input Test \$ Level; cards; A 210 A 200 A 120 B 320 B 300 B 50 C 430 C 400 ; run; /* this is the routine, the above only to get test-data */ %let no=0; proc sort in=a out=dummy nodupkey force; by test; run; data _null_; set dummy; call symput("no",_n_); call symput("n"!!put(_n_,8. -L),compress(test)); run; /* the macro is only a simple way to get it together */ /* another ...