BookmarkSubscribeRSS Feed
SASACC
Calcite | Level 5
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.
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
SPR
Quartz | Level 8 SPR
Quartz | Level 8
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
Peter_C
Rhodochrosite | Level 12
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 )
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1675 views
  • 0 likes
  • 4 in conversation