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

Hello,

I am using proc sort by _all_  so that I can know if there is a duplicate records but SAS is producing a record at the dupout which is not a duplicate by _all_.

I have tried using nodupkey and nodup, but am getting the same result. My expectations is that by using _all_ , sas will sort by all variables within the each record. In the past someone raise the same issue in this community and someone suggested using first. and last. but will this works and how do I use first. and last. with _all_?

Is there any other way to sort by _All_ ?  Any help will be highly appreciated. Thanks

 

Here is my code:

proc sort data=t nodup dupout=bc;
by _all_ ;
run;

 

proc sort data=y nodupkey dupout=z
by _all_ ;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

Are you 100% sure it's not a duplicate? As they say: "Nothing can put a knife in your back as good as your own data..."

 

1) run sort:

proc sort data=t out=t_sort;
by _all_ ;
run;

2)  execute "first-last" check:

data t_sort_check;
set t_sort;
by _all_;
_compare_ = (first.<the name of the last variable in variables list> = last.<the name of the last variable in variables list>);
run;

data t_sort_checr_result;
set t_sort_check;
where compare_ = 0;
run;

(<the name of the last variable in variables list> - replace this with proper variable name from the dataset, if you have: var1, var2, var3, ..., varN - use varN)

3) see what is in the t_sort_checr_result

 

All the best

Bart

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

1 REPLY 1
yabwon
Onyx | Level 15

Are you 100% sure it's not a duplicate? As they say: "Nothing can put a knife in your back as good as your own data..."

 

1) run sort:

proc sort data=t out=t_sort;
by _all_ ;
run;

2)  execute "first-last" check:

data t_sort_check;
set t_sort;
by _all_;
_compare_ = (first.<the name of the last variable in variables list> = last.<the name of the last variable in variables list>);
run;

data t_sort_checr_result;
set t_sort_check;
where compare_ = 0;
run;

(<the name of the last variable in variables list> - replace this with proper variable name from the dataset, if you have: var1, var2, var3, ..., varN - use varN)

3) see what is in the t_sort_checr_result

 

All the best

Bart

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



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
  • 662 views
  • 0 likes
  • 2 in conversation