I have a large dataset that looks like this:
data have;
input finalVal value1 value2 value3;
datalines;
5 1 2 5
6 26 6 10
29 4 9 1
7 35 1 7
;
I want to find which of the 3 columns match and output that to a new column
like this:
data want;
input finalVal value1 value2 value3 matching_column $;
datalines;
5 1 2 5 value3
6 26 6 10 value2
29 4 9 1 none
7 35 1 7 value3
;is this doable within a single proc sql or data step?
I was thinking I could make a series of if statements for everything, but I'm not sure if there is a more efficient way of doing this.
I would appreciate any input, thanks!
I don't understand the logic here. Please explain further. I also don't see where any "matching columns" comes into play.
Do you want the variable name or just the index?
data want;
set have;
array _search(3) value1-value3;
index = whichn(finalVal, of _search(*));
if index ne 0 then variableName = vname(_search(index));
else variableName = 'none';
run;
@raddad34 wrote:
I have a large dataset that looks like this:
data have; input finalVal value1 value2 value3; datalines; 5 1 2 5 6 26 6 10 29 4 9 1 7 35 1 7 ;I want to find which of the 3 columns match and output that to a new column
like this:
data want; input finalVal value1 value2 value3 matching_column $; datalines; 5 1 2 5 value3 6 26 6 10 value2 29 4 9 1 none 7 35 1 7 value3 ;is this doable within a single proc sql or data step?
I was thinking I could make a series of if statements for everything, but I'm not sure if there is a more efficient way of doing this.
I would appreciate any input, thanks!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.