BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
HitmonTran
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag

View solution in original post

1 REPLY 1
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 688 views
  • 0 likes
  • 2 in conversation