VarLength in spss v.22

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

VarLength in spss v.22

cesarGalicia

Hi,

I'm a new user from spss, but i really need your help.

I have this script in a .sbs program to read a database from spss ver. 22

All my variable's length of all is 4 , but when i reading the objSpssInfo.VarLength(i)
returns  8 this number is the value than i have before the aligment, i guess, this is the number of columns



These is a part of the program
  Dim lngNumCases  As Long

    Dim objSpssApp As Object
    Set objSpssApp = CreateObject("SPSS.Application16")
        Dim objDataDoc As ISpssDataDoc

        intCount=objSpssInfo.NumVariables

        For i=0 To intCount-1

                                strVarName(i) = objSpssInfo.VariableAt(i)
                                lngVarLength(i) = objSpssInfo.VarLength(i)

 'Here is the problem


Can you help me

Thanks in advance.

César .


Reply | Threaded
Open this post in threaded view
|

Re: VarLength in spss v.22

Albert-Jan Roskam-2
 
----- Original Message -----

> From: cesarGalicia <[hidden email]>
> To: [hidden email]
> Cc:
> Sent: Friday, November 28, 2014 12:04 AM
> Subject: [SPSSX-L] VarLength  in spss v.22
>
> Hi,
>
> I'm a new user from spss, but i really need your help.
>
> I have this script in a .sbs program to read a database from spss ver. 22
>
> All my variable's length of all is 4 , but when i reading the
> objSpssInfo.VarLength(i)
> returns  8 this number is the value than i have before the aligment, i
> guess, this is the number of columns
>
>
>
> These is a part of the program
>   Dim lngNumCases  As Long
>
>     Dim objSpssApp As Object
>     Set objSpssApp = CreateObject("SPSS.Application16")
>     Dim objDataDoc As ISpssDataDoc
>
>     intCount=objSpssInfo.NumVariables
>
>     For i=0 To intCount-1
>
>                 strVarName(i) = objSpssInfo.VariableAt(i)
>                 lngVarLength(i) = objSpssInfo.VarLength(i)
>

Hi, have you tried using objSpssInfo.varType? And if you just switched to SPSS v22 you should also be aware that string lenghts of files created in earlier versions (that use codepage mode by default) might triple in SPSS v22 (that uses unicode mode by default). You can SET UNICODE=OFF to prevent this, or use ALTER TYPE to "deflate" the dataset.

=====================
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: VarLength in spss v.22

Jon K Peck
The VarLength api returns the display length for the variable, which is by default 8 for a numeric variable and the actual string width (in bytes) for a string in A format.  (AHEX would be double)  It is not related to alignment.

As Albert-Jan says, the VarType api type corresponds to the variable type.  It will be zero for a numeric  variable and the string width in bytes for a string.




Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        Albert-Jan Roskam <[hidden email]>
To:        [hidden email]
Date:        12/01/2014 09:05 AM
Subject:        Re: [SPSSX-L] VarLength  in spss v.22
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




 
----- Original Message -----
> From: cesarGalicia <[hidden email]>
> To: [hidden email]
> Cc:
> Sent: Friday, November 28, 2014 12:04 AM
> Subject: [SPSSX-L] VarLength  in spss v.22
>
> Hi,
>
> I'm a new user from spss, but i really need your help.
>
> I have this script in a .sbs program to read a database from spss ver. 22
>
> All my variable's length of all is 4 , but when i reading the
> objSpssInfo.VarLength(i)
> returns  8 this number is the value than i have before the aligment, i
> guess, this is the number of columns
>
>
>
> These is a part of the program
>   Dim lngNumCases  As Long
>
>     Dim objSpssApp As Object
>     Set objSpssApp = CreateObject("SPSS.Application16")
>     Dim objDataDoc As ISpssDataDoc
>
>     intCount=objSpssInfo.NumVariables
>
>     For i=0 To intCount-1
>
>                 strVarName(i) = objSpssInfo.VariableAt(i)
>                 lngVarLength(i) = objSpssInfo.VarLength(i)
>

Hi, have you tried using objSpssInfo.varType? And if you just switched to SPSS v22 you should also be aware that string lenghts of files created in earlier versions (that use codepage mode by default) might triple in SPSS v22 (that uses unicode mode by default). You can SET UNICODE=OFF to prevent this, or use ALTER TYPE to "deflate" the dataset.

=====================
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: VarLength in spss v.22

cesarGalicia
In reply to this post by Albert-Jan Roskam-2

Hi Albert  / Jon

Thank you so much for your help.

All my Numeric variables have lenght 4

I'm trying to read the ascii data after save with the command
 
Write outfile='c:\data.dat'
ENCODE 'Locale'
TABLE /All.


Variable      Type          Lenght      Dec
Serial_id       Numeric      4              0
Gender         Numeric      4              0
Name           String       50              0
city              Numeric      4              0
Q1               Numeric      4              0
Q2               Numeric      4              0


Variable Rec   Start   End Format

Serial_id   1   1      4    F4.0
Gender     1   5      8    F4.0
Name       1   9    58    A50
city          1  59    62   F4.0
Q1           1  63    66   F4.0
Q2           1  67    70   F4.0


Thank you again

César