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!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.