How to create unique ID numbers

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How to create unique ID numbers

vstirkey
Good afternoon, I have a list of 15 digit ID numbers. I am adding cases to the file and I need to create ID numbers for the new cases. I am hoping to handle this either by adding a case number plus 1 ( last number in original file is 000000000771785, next case number will be 000000000771786 and so on OR I thought I would make the new numbers identifiable by fiscal year, with each 15 digit number beginning with 121300000000001 , then 121300000000002 and so on. Can anyone help me write the syntax for either option? Thank you for your help!
Reply | Threaded
Open this post in threaded view
|

Re: How to create unique ID numbers

kwame woei
Compute, $casenum, sum

> Op 5 feb. 2015 om 20:08 heeft "vstirkey" <[hidden email]> het volgende geschreven:
>
> Good afternoon, I have a list of 15 digit ID numbers. I am adding cases to
> the file and I need to create ID numbers for the new cases. I am hoping to
> handle this either by adding a case number plus 1 ( last number in original
> file is 000000000771785, next case number will be 000000000771786 and so on
> OR I thought I would make the new numbers identifiable by fiscal year, with
> each 15 digit number beginning with 121300000000001 , then 121300000000002
> and so on. Can anyone help me write the syntax for either option? Thank you
> for your help!
>
>
>
> --
> View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-create-unique-ID-numbers-tp5728584.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: How to create unique ID numbers

Maurice Vergeer
In reply to this post by vstirkey
If you already have existing id values, try the following untested code:

compute id_new = id_old.
if missing(id_new) id_new = lag(id_old)+1.


On Thu, Feb 5, 2015 at 8:39 PM, kwame woei <[hidden email]> wrote:

    Compute, $casenum, sum

    > Op 5 feb. 2015 om 20:08 heeft "vstirkey" <[hidden email]> het volgende geschreven:
    >
    > Good afternoon, I have a list of 15 digit ID numbers. I am adding cases to
    > the file and I need to create ID numbers for the new cases. I am hoping to
    > handle this either by adding a case number plus 1 ( last number in original
    > file is 000000000771785, next case number will be 000000000771786 and so on
    > OR I thought I would make the new numbers identifiable by fiscal year, with
    > each 15 digit number beginning with 121300000000001 , then 121300000000002
    > and so on. Can anyone help me write the syntax for either option? Thank you
    > for your help!
    >
    >
    >
    > --
    > View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-create-unique-ID-numbers-tp5728584.html
    > Sent from the SPSSX Discussion mailing list archive at Nabble.com.
    >
    > =====================
    > To manage your subscription to SPSSX-L, send a message to
    > [hidden email] (not to SPSSX-L), with no body text except the
    > command. To leave the list, send the command
    > SIGNOFF SPSSX-L
    > For a list of commands to manage subscriptions, send the command
    > INFO REFCARD

    =====================
    To manage your subscription to SPSSX-L, send a message to
    [hidden email] (not to SPSSX-L), with no body text except the
    command. To leave the list, send the command
    SIGNOFF SPSSX-L
    For a list of commands to manage subscriptions, send the command
    INFO REFCARD




--
________________________________________________
Maurice Vergeer
To contact me, see http://mauricevergeer.nl/node/5
To see my publications, see http://mauricevergeer.nl/node/1
________________________________________________


On Thu, Feb 5, 2015 at 8:08 PM, vstirkey <[hidden email]> wrote:
Good afternoon, I have a list of 15 digit ID numbers. I am adding cases to
the file and I need to create ID numbers for the new cases. I am hoping to
handle this either by adding a case number plus 1 ( last number in original
file is 000000000771785, next case number will be 000000000771786 and so on
OR I thought I would make the new numbers identifiable by fiscal year, with
each 15 digit number beginning with 121300000000001 , then 121300000000002
and so on. Can anyone help me write the syntax for either option? Thank you
for your help!



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-create-unique-ID-numbers-tp5728584.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD



--
________________________________________________
Maurice Vergeer
To contact me, see http://mauricevergeer.nl/node/5
To see my publications, see http://mauricevergeer.nl/node/1
________________________________________________
===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: How to create unique ID numbers

Jignesh Sutar
In reply to this post by vstirkey
You can construct the IDs in which ever way you think best suits the data that you are likely to receive. Having a carefully constructed ID is certainly a good idea.

How you decide to proceed would heavily depend on exactly how you expect IDs to arrive and how they are to be used going forward. 

Below is an example which tries to replicate what you describe (at least the former part). Perhaps explore the syntax below and adapt to your needs. It assumes your ID values are numeric values (rather than strings). If they are string you can just as well apply string manipulation to achieve the same.

/*************************************/.
DATA LIST FREE /ID1 (F15.0).
BEGIN DATA
1
2
4545
771785
END DATA.
DATASET NAME DS1.
/*************************************/.
ALTER TYPE ID1 (N15).
COMPUTE ID=ID1.

/*************************************/.
DATA LIST FREE /ID2 (F15.0).
BEGIN DATA
1
2
3
34
END DATA.
DATASET NAME DS2.
/*************************************/.

COMPUTE ID=ID2 + 771785 /* <---- i.e. MAX ID value from ds1 */ .
COMPUTE ID=$CASENUM + 771785 /* Alternative method if wanting to force sequential IDs */ .

DATASET ACTIVATE DS1.
ADD FILES FILE=* /FILE=DS2.





On 5 February 2015 at 19:08, vstirkey <[hidden email]> wrote:
Good afternoon, I have a list of 15 digit ID numbers. I am adding cases to
the file and I need to create ID numbers for the new cases. I am hoping to
handle this either by adding a case number plus 1 ( last number in original
file is 000000000771785, next case number will be 000000000771786 and so on
OR I thought I would make the new numbers identifiable by fiscal year, with
each 15 digit number beginning with 121300000000001 , then 121300000000002
and so on. Can anyone help me write the syntax for either option? Thank you
for your help!



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-create-unique-ID-numbers-tp5728584.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: How to create unique ID numbers

Maguin, Eugene
In reply to this post by vstirkey
The most important thing not stated is whether the cases to be added already have an id number. Simpler to suppose they don't. So when the new cases are added, the id number, which is numeric and not string, in cumulative file will be sysmis for those new cases.

Cumulative numbering.
If (sysmis(idnumber)) idnumber=lag(idnumber)+1.  /* just what others have said.


Month-year+sequence numbering.
If you choose this numbering scheme, I think it'll be easier to add the idnumber field and fill it prior to adding the new records to the cumulative file. Another little advantage is that the record sequence element (i.e., 1, 2, 3, etc.) will be equal to the $casenum value. Therefore

Compute idnumber=121300000000000+$casenum.



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of vstirkey
Sent: Thursday, February 05, 2015 2:09 PM
To: [hidden email]
Subject: How to create unique ID numbers

Good afternoon, I have a list of 15 digit ID numbers. I am adding cases to the file and I need to create ID numbers for the new cases. I am hoping to handle this either by adding a case number plus 1 ( last number in original file is 000000000771785, next case number will be 000000000771786 and so on OR I thought I would make the new numbers identifiable by fiscal year, with each 15 digit number beginning with 121300000000001 , then 121300000000002 and so on. Can anyone help me write the syntax for either option? Thank you for your help!



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-create-unique-ID-numbers-tp5728584.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: How to create unique ID numbers

David Marso
Administrator
In reply to this post by vstirkey
What is the point of a 15 digit ID number?
Just add the files,
COMPUTE ID=$CASENUM.
and be done with it!

vstirkey wrote
Good afternoon, I have a list of 15 digit ID numbers. I am adding cases to the file and I need to create ID numbers for the new cases. I am hoping to handle this either by adding a case number plus 1 ( last number in original file is 000000000771785, next case number will be 000000000771786 and so on OR I thought I would make the new numbers identifiable by fiscal year, with each 15 digit number beginning with 121300000000001 , then 121300000000002 and so on. Can anyone help me write the syntax for either option? Thank you for your help!
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?"
Reply | Threaded
Open this post in threaded view
|

Re: How to create unique ID numbers

Richard Ristow
In reply to this post by vstirkey
Two warnings -- at 02:08 PM 2/5/2015, vstirkey wrote:

>I have a list of 15 digit ID numbers.

First:  15 digits is close to the largest integer whose exact value
can be stored in the number representation that SPSS uses. You're OK
so far, and anyway the ID numbers you cite have far fewer than 15
significant digits; but don't make the ID longer, for any reason.

>I am adding cases to the file and I need to create ID numbers for
>the new cases. I am hoping to handle this either by adding a case
>number plus 1 (last number in original
>file is 000000000771785, next case number will be 000000000771786
>and so on OR I thought I would make the new numbers identifiable by
>fiscal year, with each 15 digit number beginning with
>121300000000001 , then 121300000000002 and so on.

Second, although there are ways to do it (as you've seen),
automatically assigning ID numbers should be done with caution.  It's
critically important that the same case never gets two different IDs;
and unless you're very careful that no case is added to your master
file more than once, and that you never lose the association of an ID
to a case once it's made, such ambiguities can arise very easily.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: How to create unique ID numbers

John F Hall
In reply to this post by David Marso
David's is the simplest solution.  The new variable ID will be appended to
the end of the file, but you can move it to the top.  In Variable View,
click on the row number to highlight the row, then click and hold the mouse
key down on the row number and drag it to the top of the file.

Assuming you know which cases came from which year, I would also be minded
to create a new variable YEAR, then do something like (substitute your own
values for as many years as you have data):

DO IF ID LT <value1> YEAR = 2012.
ELSE IF ID GE <value1> AND LT <value2> YEAR = 2013.
END IF.

Another way would be something like:

RECODE ID (1 thru <value1> = 2012 INTO YEAR
        /ID (<value1 + 1> thru <value2> = 2013 INTO Year.

etc etc

John F Hall (Mr)
[Retired academic survey researcher]

Email:   [hidden email]  
Website: www.surveyresearch.weebly.com  
SPSS start page:  www.surveyresearch.weebly.com/1-survey-analysis-workshop




-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
David Marso
Sent: 05 February 2015 22:01
To: [hidden email]
Subject: Re: How to create unique ID numbers

What is the point of a 15 digit ID number?
Just add the files,
COMPUTE ID=$CASENUM.
and be done with it!


vstirkey wrote
> Good afternoon, I have a list of 15 digit ID numbers. I am adding cases to
> the file and I need to create ID numbers for the new cases. I am hoping to
> handle this either by adding a case number plus 1 ( last number in
> original file is 000000000771785, next case number will be 000000000771786
> and so on OR I thought I would make the new numbers identifiable by fiscal
> year, with each 15 digit number beginning with 121300000000001 , then
> 121300000000002 and so on. Can anyone help me write the syntax for either
> option? Thank you for your help!





-----
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?"
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/How-to-create-unique-ID-number
s-tp5728584p5728589.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD