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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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