*
* @UniqueValues(values=VECTOR) series start end
* returns a vector of sorted unique values for the series over
* the indicated range.
*
* Revision Schedule
*   06/2011 Change method of detecting dups to avoid problems with
*           lags in panel calendars.
*   06/2012 Add SMPL option
*
procedure UniqueValues series start end
type series 	series
type integer 	start end
*
option vector 	*values
option series  smpl
*
local integer startl endl i
local series  copy   dups
local real    lastcopy value
*
if .not.%defined(values) {
   disp "### @UniqueValues(VALUES=vector) series start end"
   return
}
inquire(series=series) startl<<start endl<<end
if %defined(smpl)
   set copy startl endl = %if(smpl,series,%na)
else
   set copy startl endl = series
order copy startl endl
*
* Set dups to 1 if the difference is zero or machine-error.
*
set(start=(lastcopy=copy(t)-1)) dups startl endl = $
   value=%noprec(copy-lastcopy),lastcopy=copy,value
*
sample(smpl=.not.dups) copy startl endl copy
dim values(%nobs)
ewise values(i)=copy(startl+i-1)
end

