Convert string to ascii

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

Convert string to ascii

Eric Graig-2
I am trying to create a numeric ID for records in an .sav file. My strategy
was to convert respondents initials into their ascii value and then add that
value to the numeric of their birth date.  Although it appears in the help,
the ascw function generates an error.

Can anyone suggest how to convert a string to it's ascii value?

Thanks,

Eric

=====================
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: Convert string to ascii

Maguin, Eugene
Eric, could there be a typo in your message? I find no mention 'ascw' in either the help files or the syntax reference. Python??

Another scheme is to use a do repeat and assign 01 to 26 to A to Z. What difference would the ascii codes make? But the ascii equivalents are listed in appendix A of the syntax reference.

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Eric Graig
Sent: Wednesday, August 15, 2012 11:21 AM
To: [hidden email]
Subject: Convert string to ascii

I am trying to create a numeric ID for records in an .sav file. My strategy was to convert respondents initials into their ascii value and then add that value to the numeric of their birth date.  Although it appears in the help, the ascw function generates an error.

Can anyone suggest how to convert a string to it's ascii value?

Thanks,

Eric

=====================
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: Convert string to ascii

Rick Oliver-3
In reply to this post by Eric Graig-2
Since there is no "ascw" function (and AFAIK,  it does not appear in the help), a code sample that currently doesn't work might be helpful.

But why does the ID have to be numeric? If initials and birth date really make a unique ID, you could make a unique string ID by converting birth date to a string and then concatenating that with the initials. And if you really need a numeric ID you could then use Autorecode to create a numeric ID variable. For example:

string stringid (a20).
compute stringid=concat(rtrim(initials), string(birthdate, date11)).
autorecode stringid /into numericid.


Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        Eric Graig <[hidden email]>
To:        [hidden email],
Date:        08/15/2012 10:33 AM
Subject:        Convert string to ascii
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




I am trying to create a numeric ID for records in an .sav file. My strategy
was to convert respondents initials into their ascii value and then add that
value to the numeric of their birth date.  Although it appears in the help,
the ascw function generates an error.

Can anyone suggest how to convert a string to it's ascii value?

Thanks,

Eric

=====================
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: Convert string to ascii

Albert-Jan Roskam
In reply to this post by Maguin, Eugene
Maybe VB? The Python equivalent is ord and the antonym is unichr

"AscW returns the Unicode code point for the input character. This can be 0 through 65535. The returned value is independent of the culture and code page settings for the current thread."
http://msdn.microsoft.com/en-us/library/zew1e4wc%28v=vs.80%29.aspx
 
Regards,
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

From: "Maguin, Eugene" <[hidden email]>
To: [hidden email]
Sent: Wednesday, August 15, 2012 5:47 PM
Subject: Re: [SPSSX-L] Convert string to ascii

Eric, could there be a typo in your message? I find no mention 'ascw' in either the help files or the syntax reference. Python??

Another scheme is to use a do repeat and assign 01 to 26 to A to Z. What difference would the ascii codes make? But the ascii equivalents are listed in appendix A of the syntax reference.

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Eric Graig
Sent: Wednesday, August 15, 2012 11:21 AM
To: [hidden email]
Subject: Convert string to ascii

I am trying to create a numeric ID for records in an .sav file. My strategy was to convert respondents initials into their ascii value and then add that value to the numeric of their birth date.  Although it appears in the help, the ascw function generates an error.

Can anyone suggest how to convert a string to it's ascii value?

Thanks,

Eric

=====================
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: Convert string to ascii

David Marso
Administrator
In reply to this post by Eric Graig-2
I really have NO idea of why you want to do this *but* here goes.
DATA LIST FREE/ Alpha (A52).
BEGIN DATA.
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
END DATA.
VECTOR Nums (52,F3.0).
LOOP #=1 TO 52.
COMPUTE NUMS(#)=NUMBER(CHAR.SUBSTR(Alpha,#,1),PIB).
END LOOP.
LIST.

The variables are listed in the following order:

LINE   1: Alpha Nums1 Nums2 Nums3 Nums4 Nums5 Nums6 Nums7 Nums8 Nums9 Nums10 Nums11 Nums12 Nums13 Nums14 Nums15 Nums16

LINE   2: Nums17 Nums18 Nums19 Nums20 Nums21 Nums22 Nums23 Nums24 Nums25 Nums26 Nums27 Nums28 Nums29 Nums30 Nums31 Nums32 Nums33
          Nums34 Nums35 Nums36 Nums37 Nums38 Nums39 Nums40 Nums41 Nums42 Nums43 Nums44 Nums45

LINE   3: Nums46 Nums47 Nums48 Nums49 Nums50 Nums51 Nums52

       Alpha: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80
      Nums17:  81  82  83  84  85  86  87  88  89  90  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
      Nums46: 116 117 118 119 120 121 122


Number of cases read:  1    Number of cases listed:  1


Eric Graig-2 wrote
I am trying to create a numeric ID for records in an .sav file. My strategy
was to convert respondents initials into their ascii value and then add that
value to the numeric of their birth date.  Although it appears in the help,
the ascw function generates an error.

Can anyone suggest how to convert a string to it's ascii value?

Thanks,

Eric

=====================
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
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?"