Date: Mon, 18 Jul 2005 08:22:30 -0500
Reply-To: Vishal Dave <VishalDave@Affina.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Vishal Dave <VishalDave@Affina.com>
Subject: Re: formatting variables
Content-Type: text/plain; charset="US-ASCII"
Some one in the list posted same type of question last week. Here are
two different solutions proposed :
**********************************
Howie,
You can use the following macro for changing width for string variable.
The macro changes string variable name "text" to the length A50.
DEFINE !convert (vname=!TOKENS(1) /nformat=!TOKENS(1) /type=!TOKENS(1))
/* where vname= the name of the variable to change format */
/* nformat = the new format */
/* type of change ss (string to string) ns or sn where n=numeric and
s=string */
!IF (!type='ss') !THEN STRING temp1234(!nformat).
COMPUTE temp1234=!vname.
!IFEND
!IF (!type='ns') !THEN STRING temp1234(!nformat).
COMPUTE temp1234=LTRIM(STRING(!vname,F18.0)).
!IFEND
!IF (!type='sn') !THEN COMPUTE temp1234=NUMBER(!vname,F18.0).
FORMAT temp1234(!nformat).
!IFEND
MATCH FILES FILE=* /DROP=!vname.
RENAME VARIABLE (temp1234=!vname).
!ENDDEFINE.
*/////////////////////.
* EXAMPLE of how the macro is used.
!convert vname=text nformat=A50 type=ss.
Hope this helps,
Thanks,
Vishal.
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of
Howie Harshaw
Sent: Friday, July 15, 2005 10:34 AM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Variable width (string vars)
Hi,
I am importing data from a number of Excel files that contain both
numeric and string variables. I have no difficulty importing the
individual Excel files and saving them as SAV files. However, when I
attempt to merge them, I run into difficulty with some of the string
variables, as they are of different lengths. What I am hoping to do is
set the variable length for the string variables before I merge the
files (to say a common length of 50).
I have checked the syntax manual, but have been unable to find the
appropriate command.
Thanks,
- Howie
--
*******************************************
Hi Howie,
I've encountered this issue a couple times in the past as well.
Unfortunately, I think this is an issue with rests with how Excel
instructs SPSS relative to the file definitions (but I'll leave it to
others at SPSS to clarify that).
What I've done is simply redefine the variable in one or the other files
when I encounter the problem. It may not be the most elegant way to
tackle the obstacle, but essentially when I see the discrepancy, I
compute a new string in the active file which conforms to the length
specified in the external file. As SPSS won't allow duplicate variable
names, the new variable I create is called something like "oldvar_1"
where I use the suffix "_1" to designate the new variable.
Finally, I use the MATCH FILES command with the DROP subcommand to drop
the original variable, and then the RENAME command to rename the new
variable to match the old variable in the external file. Following is
an (untested) example assuming the variable in the current file is
string of 18 length, while the *external file* has the variable defined
at 20.
STRING oldvar_1 (A20).
COMPUTE oldvar_1 = oldvar.
MATCH FILES FILE = * /DROP = oldvar.
EXE.
RENAME VARIABLES (oldvar_1 = oldvar).
ADD FILES FILE = 'c:\path\..\external_file.sav'.
HTH
JN
>>> Howie Harshaw <harshaw@interchange.ubc.ca> 7/15/2005 10:34 AM >>>
Hi,
I am importing data from a number of Excel files that contain both
numeric and string variables. I have no difficulty importing the
individual Excel files and saving them as SAV files. However, when I
attempt to merge them, I run into difficulty with some of the string
variables, as they are of different lengths. What I am hoping to do is
set the variable length for the string variables before I merge the
files (to say a common length of 50).
I have checked the syntax manual, but have been unable to find the
appropriate command.
Thanks,
- Howie
**************************************************
Hope this helps,
Vishal Dave
Analyst, ACRM
AFFINA, LLC
2001, Ruppman PLaza
Peoria, IL 61614
(309) 679-4481
vishaldave@affina.com
"IF YOU CAN'T PROVE IT, MEASURE IT."
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of
Dana
Sent: Sunday, July 17, 2005 9:49 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: formatting variables
Is there a way to change the width of a string variable using syntax?
The problem is I am opening Excel files in SPSS and then trying to merge
them, but when I open the Excel files in SPSS the same variables in
different files are assigned different string widths. So I can't merge
them.
Thanks,
Dana