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.
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;
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.
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.
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.
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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.