contract a page with uniquevals?
Posted: Fri Sep 18, 2015 4:37 am
Can somebody help me speed up the following code snippet? I want to pagecontract to leave only unique values. However, I cant figure out how to use @uniquevals effectively, and this loop is dragging as there are millions of observations in the workfile. The intention is to drop all observations which dont have unique entries in the alpha 'name' (only the first observed instance of each name string are kept, sequential ones are dropped: ordering unimportant however):
Help appreciated as always! Best wishes to all.
Charlie
**************EDIT**************
This is faster, but I feel that it can be faster still....:
Code: Select all
genr uniquedum = 1
for !a = 2 to @obsrange
for !b = !a-1 to 1 step -1
if name(!a) = name(!b) then
uniquedum(!a) = 0
!b = 1
endif
next
!c = (!a/@obsrange)*100
statusline !c % filtering of unique values
next
pagecontract if uniquedum = 1Charlie
**************EDIT**************
This is faster, but I feel that it can be faster still....:
Code: Select all
svector unique_svector=@uniquevals(name)
for !a = 1 to @rows(unique_svector)
for !b = 1 to @obsrange
if unique_svector(!a)=name(!b) then
uniquedum(!b) = 0
!b = @obsrange
endif
next
!c = (!a/@rows(unique_svector))*100
statusline !c % filtering of unique values
next
pagecontract if uniquedum = 1