Variable length to maximum

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

Variable length to maximum

Manmit Shrimali-2
This is rather very simple question. However, after lot of research I
still could not find the answer. Can please anyone provide me syntax for
setting the variable length to maximum i.e numeric to 40 and string to
255.

 

Right now I have to manually go in width column of variable view and set
it to maximum. I have to set it to maximum as when I have wave 2 data to
merge, the length should be the same.

 

Thanks in advance.

 

Manmit
Reply | Threaded
Open this post in threaded view
|

SV: Variable length to maximum

Staffan Lindberg
You can do this with the FORMAT statement, i.e.

FORMAT VARNUM (F40.0).
FORMAT VARSTRING (A255).

best

Staffan Lindberg
National Institute of Public Health
Sweden

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För Manmit
Shrimali
Skickat: den 28 juli 2006 14:21
Till: [hidden email]
Ämne: Variable length to maximum


This is rather very simple question. However, after lot of research I still
could not find the answer. Can please anyone provide me syntax for setting
the variable length to maximum i.e numeric to 40 and string to 255.



Right now I have to manually go in width column of variable view and set it
to maximum. I have to set it to maximum as when I have wave 2 data to merge,
the length should be the same.



Thanks in advance.



Manmit
Reply | Threaded
Open this post in threaded view
|

Re: Variable length to maximum

Manmit Shrimali-2
In reply to this post by Manmit Shrimali-2
Thanks staffan but the problem is that I need to do for all variables. I have 550 numeric variables and 39 string variables. Can I use something like all varnum and all var string etc..

Please help.

-----Original Message-----
From: Staffan Lindberg [mailto:[hidden email]]
Sent: Friday, July 28, 2006 5:59 PM
To: Manmit Shrimali; [hidden email]
Subject: SV: Variable length to maximum

You can do this with the FORMAT statement, i.e.

FORMAT VARNUM (F40.0).
FORMAT VARSTRING (A255).

best

Staffan Lindberg
National Institute of Public Health
Sweden

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För Manmit
Shrimali
Skickat: den 28 juli 2006 14:21
Till: [hidden email]
Ämne: Variable length to maximum


This is rather very simple question. However, after lot of research I still
could not find the answer. Can please anyone provide me syntax for setting
the variable length to maximum i.e numeric to 40 and string to 255.



Right now I have to manually go in width column of variable view and set it
to maximum. I have to set it to maximum as when I have wave 2 data to merge,
the length should be the same.



Thanks in advance.



Manmit
Reply | Threaded
Open this post in threaded view
|

SV: Variable length to maximum

Staffan Lindberg
OK!

You can use the TO functions when the variables are consecutively placed
(numerical or string) i.e.

Format Varnum1 to VarnumX (F40.0).
Format Varstring1 to VarstringX (A255).

This can be somewhat tedious, if you have every other numerical and every
other string. Perhaps it is possible to use a script or something similar.
Perhaps some script wizard on the list could help you.

best

Staffan Lindberg
National Institute of Public Health
Sweden

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För Manmit
Shrimali
Skickat: den 28 juli 2006 14:35
Till: [hidden email]
Ämne: Re: Variable length to maximum


Thanks staffan but the problem is that I need to do for all variables. I
have 550 numeric variables and 39 string variables. Can I use something like
all varnum and all var string etc..

Please help.

-----Original Message-----
From: Staffan Lindberg [mailto:[hidden email]]
Sent: Friday, July 28, 2006 5:59 PM
To: Manmit Shrimali; [hidden email]
Subject: SV: Variable length to maximum

You can do this with the FORMAT statement, i.e.

FORMAT VARNUM (F40.0).
FORMAT VARSTRING (A255).

best

Staffan Lindberg
National Institute of Public Health
Sweden

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För Manmit
Shrimali
Skickat: den 28 juli 2006 14:21
Till: [hidden email]
Ämne: Variable length to maximum


This is rather very simple question. However, after lot of research I still
could not find the answer. Can please anyone provide me syntax for setting
the variable length to maximum i.e numeric to 40 and string to 255.



Right now I have to manually go in width column of variable view and set it
to maximum. I have to set it to maximum as when I have wave 2 data to merge,
the length should be the same.



Thanks in advance.



Manmit
Reply | Threaded
Open this post in threaded view
|

Re: Variable length to maximum

Mike P-5
In reply to this post by Manmit Shrimali-2
If your running in V14,

A python script would do this easily by looking at the variable type

MIKE

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Manmit Shrimali
Sent: 28 July 2006 13:35
To: [hidden email]
Subject: Re: Variable length to maximum

Thanks staffan but the problem is that I need to do for all variables. I have 550 numeric variables and 39 string variables. Can I use something like all varnum and all var string etc..

Please help.

-----Original Message-----
From: Staffan Lindberg [mailto:[hidden email]]
Sent: Friday, July 28, 2006 5:59 PM
To: Manmit Shrimali; [hidden email]
Subject: SV: Variable length to maximum

You can do this with the FORMAT statement, i.e.

FORMAT VARNUM (F40.0).
FORMAT VARSTRING (A255).

best

Staffan Lindberg
National Institute of Public Health
Sweden

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För Manmit Shrimali
Skickat: den 28 juli 2006 14:21
Till: [hidden email]
Ämne: Variable length to maximum


This is rather very simple question. However, after lot of research I still could not find the answer. Can please anyone provide me syntax for setting the variable length to maximum i.e numeric to 40 and string to 255.



Right now I have to manually go in width column of variable view and set it to maximum. I have to set it to maximum as when I have wave 2 data to merge, the length should be the same.



Thanks in advance.



Manmit

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: Variable length to maximum

Manmit Shrimali-2
In reply to this post by Manmit Shrimali-2
Sorry...i do not have v14. also I do not know python.

Anything in syntax?

-----Original Message-----
From: Michael Pearmain [mailto:[hidden email]]
Sent: Friday, July 28, 2006 6:24 PM
To: Manmit Shrimali; [hidden email]
Subject: RE: Re: Variable length to maximum

If your running in V14,

A python script would do this easily by looking at the variable type

MIKE

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Manmit Shrimali
Sent: 28 July 2006 13:35
To: [hidden email]
Subject: Re: Variable length to maximum

Thanks staffan but the problem is that I need to do for all variables. I have 550 numeric variables and 39 string variables. Can I use something like all varnum and all var string etc..

Please help.

-----Original Message-----
From: Staffan Lindberg [mailto:[hidden email]]
Sent: Friday, July 28, 2006 5:59 PM
To: Manmit Shrimali; [hidden email]
Subject: SV: Variable length to maximum

You can do this with the FORMAT statement, i.e.

FORMAT VARNUM (F40.0).
FORMAT VARSTRING (A255).

best

Staffan Lindberg
National Institute of Public Health
Sweden

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För Manmit Shrimali
Skickat: den 28 juli 2006 14:21
Till: [hidden email]
Ämne: Variable length to maximum


This is rather very simple question. However, after lot of research I still could not find the answer. Can please anyone provide me syntax for setting the variable length to maximum i.e numeric to 40 and string to 255.



Right now I have to manually go in width column of variable view and set it to maximum. I have to set it to maximum as when I have wave 2 data to merge, the length should be the same.



Thanks in advance.



Manmit

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: Variable length to maximum

Mike P-5
In reply to this post by Manmit Shrimali-2
I don't have time to write the python code for you at test it fully,

But I expect it would look something like the following; Might be  a good starting point for some else to finish?

Begin program.
import spss
spss.Submit("GET FILE = 'C:/Program Files/SPSS/Employee data.sav'.")
varList=[]
for i in range(spss.GetVariableCount()):
        if spss.GetVariableType(i)=='0':
                varList.append(spss.GetVariableName(i))
if len(varList):
        spss.Submit("FORMAT " + " ".join(varList) + "(F40.0). " + ".")
End program.

HTH

Mike


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Manmit Shrimali
Sent: 28 July 2006 13:35
To: [hidden email]
Subject: Re: Variable length to maximum

Thanks staffan but the problem is that I need to do for all variables. I have 550 numeric variables and 39 string variables. Can I use something like all varnum and all var string etc..

Please help.

-----Original Message-----
From: Staffan Lindberg [mailto:[hidden email]]
Sent: Friday, July 28, 2006 5:59 PM
To: Manmit Shrimali; [hidden email]
Subject: SV: Variable length to maximum

You can do this with the FORMAT statement, i.e.

FORMAT VARNUM (F40.0).
FORMAT VARSTRING (A255).

best

Staffan Lindberg
National Institute of Public Health
Sweden

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För Manmit Shrimali
Skickat: den 28 juli 2006 14:21
Till: [hidden email]
Ämne: Variable length to maximum


This is rather very simple question. However, after lot of research I still could not find the answer. Can please anyone provide me syntax for setting the variable length to maximum i.e numeric to 40 and string to 255.



Right now I have to manually go in width column of variable view and set it to maximum. I have to set it to maximum as when I have wave 2 data to merge, the length should be the same.



Thanks in advance.



Manmit

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: SV: Variable length to maximum

Oliver, Richard
In reply to this post by Staffan Lindberg
Using Python in SPSS 14, you can build lists of variables based on type (e.g., string vs. numeric) and use those lists of variable names in commands -- but you cannot change the defined width of a string variable via syntax. (The ability to change the defined width of a stinng variable in the Data Editor is not directly supported in syntax, although there is a workaround that involves creating new string variables of the desired width and then deleting the old ones).

Are you trying to set the print/write format of the variables, or just the width of the Data Editor columns? For the latter, you would use VARIABLE WIDTH, which doesn't care about data type or format.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Staffan Lindberg
Sent: Friday, July 28, 2006 7:48 AM
To: [hidden email]
Subject: SV: Variable length to maximum

OK!

You can use the TO functions when the variables are consecutively placed (numerical or string) i.e.

Format Varnum1 to VarnumX (F40.0).
Format Varstring1 to VarstringX (A255).

This can be somewhat tedious, if you have every other numerical and every other string. Perhaps it is possible to use a script or something similar.
Perhaps some script wizard on the list could help you.

best

Staffan Lindberg
National Institute of Public Health
Sweden

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För Manmit Shrimali
Skickat: den 28 juli 2006 14:35
Till: [hidden email]
Ämne: Re: Variable length to maximum


Thanks staffan but the problem is that I need to do for all variables. I have 550 numeric variables and 39 string variables. Can I use something like all varnum and all var string etc..

Please help.

-----Original Message-----
From: Staffan Lindberg [mailto:[hidden email]]
Sent: Friday, July 28, 2006 5:59 PM
To: Manmit Shrimali; [hidden email]
Subject: SV: Variable length to maximum

You can do this with the FORMAT statement, i.e.

FORMAT VARNUM (F40.0).
FORMAT VARSTRING (A255).

best

Staffan Lindberg
National Institute of Public Health
Sweden

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För Manmit Shrimali
Skickat: den 28 juli 2006 14:21
Till: [hidden email]
Ämne: Variable length to maximum


This is rather very simple question. However, after lot of research I still could not find the answer. Can please anyone provide me syntax for setting the variable length to maximum i.e numeric to 40 and string to 255.



Right now I have to manually go in width column of variable view and set it to maximum. I have to set it to maximum as when I have wave 2 data to merge, the length should be the same.



Thanks in advance.



Manmit
Reply | Threaded
Open this post in threaded view
|

AW: Re: Variable length to maximum

Georg Maubach
In reply to this post by Manmit Shrimali-2
Hi Manmit,

You could have a look a the web site of Raynald Levesque http://www.spsstools.net. There you can find a macro called "variable type.sps". It does what you want and will run on SPSS 11.0+.

Regards

Georg Maubach
Market Analyst


-----Ursprüngliche Nachricht-----
Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von Manmit Shrimali
Gesendet: Freitag, 28. Juli 2006 15:01
An: [hidden email]
Betreff: Re: Variable length to maximum

Sorry...i do not have v14. also I do not know python.

Anything in syntax?

-----Original Message-----
From: Michael Pearmain [mailto:[hidden email]]
Sent: Friday, July 28, 2006 6:24 PM
To: Manmit Shrimali; [hidden email]
Subject: RE: Re: Variable length to maximum

If your running in V14,

A python script would do this easily by looking at the variable type

MIKE

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Manmit Shrimali
Sent: 28 July 2006 13:35
To: [hidden email]
Subject: Re: Variable length to maximum

Thanks staffan but the problem is that I need to do for all variables. I have 550 numeric variables and 39 string variables. Can I use something like all varnum and all var string etc..

Please help.

-----Original Message-----
From: Staffan Lindberg [mailto:[hidden email]]
Sent: Friday, July 28, 2006 5:59 PM
To: Manmit Shrimali; [hidden email]
Subject: SV: Variable length to maximum

You can do this with the FORMAT statement, i.e.

FORMAT VARNUM (F40.0).
FORMAT VARSTRING (A255).

best

Staffan Lindberg
National Institute of Public Health
Sweden

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För Manmit Shrimali
Skickat: den 28 juli 2006 14:21
Till: [hidden email]
Ämne: Variable length to maximum


This is rather very simple question. However, after lot of research I still could not find the answer. Can please anyone provide me syntax for setting the variable length to maximum i.e numeric to 40 and string to 255.



Right now I have to manually go in width column of variable view and set it to maximum. I have to set it to maximum as when I have wave 2 data to merge, the length should be the same.



Thanks in advance.



Manmit

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email ______________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: Variable length to maximum

Hector Maletta
Manmit:
This message deals first with the change in formats, but then jumps to the
real issue: your problem is not with formats but with string variable
LENGTH, quite a different matter.

1. A HOMESPUN SOLUTION FOR FORMATS
I don't have time now to work out a macro for this, and anyway it is perhaps
not worth it for a task to be performed only once, but you can do it in a
homespun way like this. If you have some way to rapidly recognize by name
which variables are strings, you can open the variable information icon in
the toolbar (the small vertical ladder with a question mark), select all
variables (or all string variables) and click PASTE. This will copy the list
of variables into your active syntax window (or a new one if you do not one
already open). Then group the variables in two lists, one for numerical and
one for string variables, and write the keywords at the front and end of
each list, such as:
FORMATS str1 str2 str3 str4 str5 ..... str289 (A255).
FORMATS num1 num2 num3 num4 .........num 876 (F40.0).

2. THE REAL PROBLEM IS NOT FORMATS:
However, from your original question I tend to infer our problem is not with
the FORMAT (the visible number of places) in the variables but the internal
LENGTH of string variables.
To merge files, numerical variables need no adjustment: all are internally
held at the maximum precision allowed by SPSS. But string variables should
have the same LENGTH. The visible FORMAT is not important: the resulting
merged file will show the format of the first file named in the merge list.
The length of string variables is determined at their creation, with the
STRING command. One possible solution for your problem is to create new
string variables with length and copy the old strings into them. Another is
going to the data editor variable view and manually change the WIDTH cell of
all string variables to 255.
Hector



-----Mensaje original-----
De: SPSSX(r) Discussion [mailto:[hidden email]] En nombre de Georg
Maubach
Enviado el: Friday, July 28, 2006 10:10 AM
Para: [hidden email]
Asunto: AW: Re: Variable length to maximum

Hi Manmit,

You could have a look a the web site of Raynald Levesque
http://www.spsstools.net. There you can find a macro called "variable
type.sps". It does what you want and will run on SPSS 11.0+.

Regards

Georg Maubach
Market Analyst


-----Ursprüngliche Nachricht-----
Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von
Manmit Shrimali
Gesendet: Freitag, 28. Juli 2006 15:01
An: [hidden email]
Betreff: Re: Variable length to maximum

Sorry...i do not have v14. also I do not know python.

Anything in syntax?

-----Original Message-----
From: Michael Pearmain [mailto:[hidden email]]
Sent: Friday, July 28, 2006 6:24 PM
To: Manmit Shrimali; [hidden email]
Subject: RE: Re: Variable length to maximum

If your running in V14,

A python script would do this easily by looking at the variable type

MIKE

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Manmit Shrimali
Sent: 28 July 2006 13:35
To: [hidden email]
Subject: Re: Variable length to maximum

Thanks staffan but the problem is that I need to do for all variables. I
have 550 numeric variables and 39 string variables. Can I use something like
all varnum and all var string etc..

Please help.

-----Original Message-----
From: Staffan Lindberg [mailto:[hidden email]]
Sent: Friday, July 28, 2006 5:59 PM
To: Manmit Shrimali; [hidden email]
Subject: SV: Variable length to maximum

You can do this with the FORMAT statement, i.e.

FORMAT VARNUM (F40.0).
FORMAT VARSTRING (A255).

best

Staffan Lindberg
National Institute of Public Health
Sweden

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För Manmit
Shrimali
Skickat: den 28 juli 2006 14:21
Till: [hidden email]
Ämne: Variable length to maximum


This is rather very simple question. However, after lot of research I still
could not find the answer. Can please anyone provide me syntax for setting
the variable length to maximum i.e numeric to 40 and string to 255.



Right now I have to manually go in width column of variable view and set it
to maximum. I have to set it to maximum as when I have wave 2 data to merge,
the length should be the same.



Thanks in advance.



Manmit

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The service is powered
by MessageLabs. For more information on a proactive anti-virus service
working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: Variable length to maximum

Oliver, Richard
In reply to this post by Manmit Shrimali-2
Although you can set the format of a numeric variable to F40, on most operating systems only the first 16 digits are going to mean anything.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Manmit Shrimali
Sent: Friday, July 28, 2006 8:01 AM
To: [hidden email]
Subject: Re: Variable length to maximum

Sorry...i do not have v14. also I do not know python.

Anything in syntax?

-----Original Message-----
From: Michael Pearmain [mailto:[hidden email]]
Sent: Friday, July 28, 2006 6:24 PM
To: Manmit Shrimali; [hidden email]
Subject: RE: Re: Variable length to maximum

If your running in V14,

A python script would do this easily by looking at the variable type

MIKE

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Manmit Shrimali
Sent: 28 July 2006 13:35
To: [hidden email]
Subject: Re: Variable length to maximum

Thanks staffan but the problem is that I need to do for all variables. I have 550 numeric variables and 39 string variables. Can I use something like all varnum and all var string etc..

Please help.

-----Original Message-----
From: Staffan Lindberg [mailto:[hidden email]]
Sent: Friday, July 28, 2006 5:59 PM
To: Manmit Shrimali; [hidden email]
Subject: SV: Variable length to maximum

You can do this with the FORMAT statement, i.e.

FORMAT VARNUM (F40.0).
FORMAT VARSTRING (A255).

best

Staffan Lindberg
National Institute of Public Health
Sweden

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För Manmit Shrimali
Skickat: den 28 juli 2006 14:21
Till: [hidden email]
Ämne: Variable length to maximum


This is rather very simple question. However, after lot of research I still could not find the answer. Can please anyone provide me syntax for setting the variable length to maximum i.e numeric to 40 and string to 255.



Right now I have to manually go in width column of variable view and set it to maximum. I have to set it to maximum as when I have wave 2 data to merge, the length should be the same.



Thanks in advance.



Manmit

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email ______________________________________________________________________