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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.