HI all,
I have an excel sheet with infinite amount of columns added weekly. I need to find if the additional columns added weekly have the same values of existing ones.
Here is a sample dataset:
data one;
input $week1 $week2 $week3;
datalines;
cat human cat
dog bird human
mouse fish horse
human lizard rabbit
;
run;
As you can see "human" occurred 3 times (week1 ,2 ,3) and "cat" occurred 2 times(week 1,3). How can I output a dataset that can identify these duplicates? thank you
please try the below code which will output the dataset with count variable to check the dupliates
data one;
input week1$ week2$ week3$;
datalines;
cat human cat
dog bird human
mouse fish horse
human lizard rabbit
;
run;
data two;
set one;
week='week1';
values=week1;
output;
week='week2';
values=week2;
output;
week='week3';
values=week3;
output;
run;
proc sort data=two;
by values;
run;
data the;
do until(last.values);
set two;
by values;
retain count;
if first.values then count=1;
else count+1;
end;
do until(last.values);
set two;
by values;
output;
end;
run;
please try the below code which will output the dataset with count variable to check the dupliates
data one;
input week1$ week2$ week3$;
datalines;
cat human cat
dog bird human
mouse fish horse
human lizard rabbit
;
run;
data two;
set one;
week='week1';
values=week1;
output;
week='week2';
values=week2;
output;
week='week3';
values=week3;
output;
run;
proc sort data=two;
by values;
run;
data the;
do until(last.values);
set two;
by values;
retain count;
if first.values then count=1;
else count+1;
end;
do until(last.values);
set two;
by values;
output;
end;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.