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

Hello

I have a data set with one field and 2 rows.

In both rows there is same value "601_15013150_10_3021_604E3"

I am doing proc sort nodupkey and I still get 2 rows!!

 

May anyone help to solve the problem??

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

You don't provide any code nor sample data. Proc Sort Nodupkey just works - see below. If you don't get the expected result then either the data is different or something in your code isn't as it should.

For the data: Leading blanks or some hidden whitespace characters (characters that don't print) could make the strings different.

data have;
  input var $20.;
  output;
  output;
  datalines;
601_15013150_10_3021_604E3
;

proc sort data=have out=want nodupkey;
  by var;
run;

proc print data=want;
run;

Patrick_0-1626776209227.png

 

View solution in original post

5 REPLIES 5
andreas_lds
Jade | Level 19

Please post data in usable form and show the log.

Patrick
Opal | Level 21

You don't provide any code nor sample data. Proc Sort Nodupkey just works - see below. If you don't get the expected result then either the data is different or something in your code isn't as it should.

For the data: Leading blanks or some hidden whitespace characters (characters that don't print) could make the strings different.

data have;
  input var $20.;
  output;
  output;
  datalines;
601_15013150_10_3021_604E3
;

proc sort data=have out=want nodupkey;
  by var;
run;

proc print data=want;
run;

Patrick_0-1626776209227.png

 

Ronein
Meteorite | Level 14
So the conclusion is to use proc sort nodupkey on numeric fields or on compressed char (not use it on non compressed chars!!)
Patrick
Opal | Level 21

@Ronein wrote:
So the conclusion is to use proc sort nodupkey on numeric fields or on compressed char (not use it on non compressed chars!!)

@Ronein No, that's definitely not the conclusion. It's: "Know your Data".

ballardw
Super User

Yep.

 

I had an analogous behavior of getting "two identical values" (actually more than two, one for each level of a variable).

Traced it back that the file exported by the source for one of the sites collecting the data were exported as " the value" and "the value" for the others. So somehow one site had values with a leading space inserted into all of its values.

But the values in SAS are not the same with a leading space. (Actually this is only one of 100's of cases where the data provided does not actually match the provided data dictionary and field descriptions from that source. They don't update the dictionary as often as they change data fields).

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
  • 5 replies
  • 2114 views
  • 3 likes
  • 4 in conversation