BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Miracle
Barite | Level 11

Hi there.

 

Can I please ask how can I return a conditional max value across columns?

 

Let say I have a=1, b=10, c=98, d=99, e=99, f=98, g=20, h=.

and I would like another new column i.e. max=20.

 

Thank you very much.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Miracle
Barite | Level 11

Hi @RW9

Sorry for the late reply and failing to make the question clearer in the first place.

Just ran your code and with a little change I managed to get it worked. 

Again thank you very much.

data want;
	a=1; b=10; c=98; d=99; e=98; f=98; g=20; h=.;
	array rep{8} a b c d e f g h;
	array act{8};
	do i=1 to 8;
	act{i}=ifn(rep{i}>90,.,rep{i});
	end;
	new_var=max(of act[*]);
	drop i act:;
run;

 

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Something like:

new_variable=max(a,b,c,d,e,f,g,h);

For better code, please post test data in the form of a datastep covering all permutations, and what the output should look like.

Miracle
Barite | Level 11

Hi @RW9 thank you very much for the quick reply.

 

new_variable=99 if I use new_variable=max(a,b,c,d,e,f,g,h) when numeric variables of a=1, b=10, c=98, d=99, e=99, f=98, g=20, h=.

 

But I need 20 to be returned given this particular case only in a datastep.

 

Thank you very much.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

This is why I ask for test data and required output.  I can't see any logical reason why 20 would be the maximum value from that set of variables:

a=1, b=10, c=98, d=99, e=99, f=98, g=20, h=.

 

Do you mean anything 90 or above is missing?  Then maybe:

data want;
  a=1; b=10; c=98; d=99; e=98; f=98; g=20; h=.;
  array rep{7} a b c d e f g h;
  array act{7};
  do i=1 to 7;
    act=ifn(rep{i}>90,.,rep{i});
  end;
  new_var=max(of act);
run; 

I don't have access to SAS at the moment to test the code, but something like that should work.

Miracle
Barite | Level 11

Hi @RW9

Sorry for the late reply and failing to make the question clearer in the first place.

Just ran your code and with a little change I managed to get it worked. 

Again thank you very much.

data want;
	a=1; b=10; c=98; d=99; e=98; f=98; g=20; h=.;
	array rep{8} a b c d e f g h;
	array act{8};
	do i=1 to 8;
	act{i}=ifn(rep{i}>90,.,rep{i});
	end;
	new_var=max(of act[*]);
	drop i act:;
run;

 

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 2189 views
  • 1 like
  • 2 in conversation