BookmarkSubscribeRSS Feed
mfisher
Fluorite | Level 6

Proc distance allows the use of an ID statement with a BY statement, as long as ID is character and they are sorted in the same order within BY.

The attached code "Distance with character year as ID" works fine (year is prefixed with Y).

The second attached code,  "Distance with numeric year as ID" (no prefix, but year is input as character) returns the error:

"ERROR: The ID variable must have the same values in the same order in each BY group."

  Any ideas why?

5 REPLIES 5
PGStats
Opal | Level 21

I noticed the same thing. I guess this restriction simplifies the generation of column names in the distance matrix and makes the names more previsible. The error message could be a tad clearer though.Smiley Wink

PG

PG
mfisher
Fluorite | Level 6

PG,

Here's an interesting twist--if you have only 1 BY group, the code works.  Columns are named with an underscore before the year, e.g., _2008.

Mark

PGStats
Opal | Level 21

Very interesting indeed. So, what might have been construed as a feature is thus an error, since it makes the procedure behaviour inconsistent. Your finding might explain the error message as well. I think that the DISTANCE procedure, when it gets to the second BY-group, checks the ID values against the variable names established during the first BY-group, and finds that they don't match (i.e. '2004' against '_2004'), thus the message "The ID variable must have the same values in the same order in each BY group." Seems like they simply omitted to translate ID values into variable names before doing the comparison.

PG

PG
mfisher
Fluorite | Level 6

I agree.

Shall I formally report this to SAS, or is posting here good enough?

PGStats
Opal | Level 21

As far as I know, you must report the bug to Tech Support, but you can refer them to this discussion for the details. - PG

PG

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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