DATA Step, Macro, Functions and more

Value from Coloumn Name

Reply
Occasional Contributor
Posts: 15

Value from Coloumn Name

Hi,

I have a dataset(name : new) which has 4 coloumns(c1 , c2 , c3 ,c4).
c4 coloumn consists the name of the coloumns ( c2,c1,.......).
please see example below:

Dataset: New
c1 c2 c3 c4
1 2 3 c2
1 3 5 c1

I did as follow:
data a;
set new;
t1 = max(0,c1 - c4);
run;

Here I want C4 to be replaced with the value. Meaning in the first row , the value for c4 is c2 so I want value of c2(Value of C2 : 2) to be substituted and so on...

Please help me .

Thanks.
Super Contributor
Super Contributor
Posts: 3,174

Re: Value from Coloumn Name

Have a look at the VVALUE / VVALUEX function.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

return value of variable site:sas.com Message was edited by: sbb
Super Contributor
Super Contributor
Posts: 365

Re: Value from Coloumn Name

Hello SASAcc,

I am not sure that understand you correctly. What do you mean by t1 = max(0,c1 - c4);?

Is this t1 = max(0,c1,c2,c3);
or t1 = max(0,c1-c3):?

Using c4 is impossible because c1, c2, c3 are numeric and c4 is character.

Anyway this my solution:
[pre]
Data New;
input c1 c2 c3 c4 $;
datalines;
1 2 3 c2
1 3 5 c1
run;
data a;
set new;
t1 = max(0, c1,c2,c3);
if c4="c2" then c2=t1;
else if c4="c1" then c1=t1;
drop t1;
run;
[/pre]
Sincerely,
SPR
Valued Guide
Posts: 2,175

Re: Value from Coloumn Name

please explain why C4 is to be considered for the MAX()
The value it holds seems to be a pointer to one of the other C(n) columns - so including the value to which C4 points will not introduce anything larger than MAX( of C1-C3 )
Ask a Question
Discussion stats
  • 3 replies
  • 147 views
  • 0 likes
  • 4 in conversation