Help using Base SAS procedures

Strange error with Proc Distance

Reply
Contributor
Posts: 58

Strange error with Proc Distance

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?

Attachment
Attachment
Respected Advisor
Posts: 4,651

Re: Strange error with Proc Distance

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
Contributor
Posts: 58

Re: Strange error with Proc Distance

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

Respected Advisor
Posts: 4,651

Re: Strange error with Proc Distance

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
Contributor
Posts: 58

Re: Strange error with Proc Distance

I agree.

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

Respected Advisor
Posts: 4,651

Re: Strange error with Proc Distance

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
Ask a Question
Discussion stats
  • 5 replies
  • 215 views
  • 0 likes
  • 2 in conversation