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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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