Quantcast

Syntax to Auto relable, with specific labeling for duplicates

classic Classic list List threaded Threaded
5 messages Options
sb
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Syntax to Auto relable, with specific labeling for duplicates

sb
Hello,

I have a dataset with case ID's that are unique to the project, which need to be kept. However, there are cases that have the same ID, which also need to be kept. I want to create a new id that will number the cases 1 - 4000, however, utilize the same ID for the duplicates. This would show the total number of cases, not including duplicates.

For example:
 ID      New ID
x20      1
x25     2
x30     3
x30     3
x30     3
x35     4
x40     5

Any suggestions on how to do this easily with syntax? I have 4000 cases & would prefer to not do it by hand & avoid any mistakes.
Thanks!
-Sherah
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax to Auto relable, with specific labeling for duplicates

Andy W
This is a FAQ, see example syntax below.

**********************************.
SORT CASES BY Id.
DO IF $casenum = 1.
  COMPUTE NewId = 1.
ELSE IF Id = LAG(ID).
  COMPUTE NewId = LAG(NewId).
ELSE.
  COMPUTE NewId = LAG(NewId) + 1.
END IF.
EXECUTE.
**********************************.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax to Auto relable, with specific labeling for duplicates

David Marso
Administrator
In reply to this post by sb
See LAG function.

IF $CASENUM EQ 1 New_ID=1.
IF ID EQ LAG(ID) New_ID=LAG(New_ID) .
IF MISSING(New_ID) New_ID=LAG(New_ID) + 1.

OR:

COMPUTE New_ID=SUM(LAG(New_ID),MAX(ID NE LAG(ID), $CASENUM EQ 1)).
HTH.
---

sb wrote
Hello,

I have a dataset with case ID's that are unique to the project, which need to be kept. However, there are cases that have the same ID, which also need to be kept. I want to create a new id that will number the cases 1 - 4000, however, utilize the same ID for the duplicates. This would show the total number of cases, not including duplicates.

For example:
 ID      New ID
x20      1
x25     2
x30     3
x30     3
x30     3
x35     4
x40     5

Any suggestions on how to do this easily with syntax? I have 4000 cases & would prefer to not do it by hand & avoid any mistakes.
Thanks!
-Sherah
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
sb
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax to Auto relable, with specific labeling for duplicates

sb
Perfect! The second method you supplied worked just as I hoped!
Thank you for your quick & thorough response!
-Sherah
sb
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax to Auto relable, with specific labeling for duplicates

sb
In reply to this post by Andy W
Thank you for your help! I had made several efforts to find the information, but must have been wording it incorrectly. Thank you for your quick reply!
Loading...