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 )

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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