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: Call for Content

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!

Submit your idea!

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