Saving data with one space between variables

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

Saving data with one space between variables

fevziesen
Hi all,

I need to save my sav file as .txt format but with one space between
variables. What do you recommend?



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Saving-data-with-one-space-between-variables-tp5728472.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
Reply | Threaded
Open this post in threaded view
|

Re: Saving data with one space between variables

Andreas Sprenger
Hi,
why not using WRITE. Say you have a variable ID (range 1-99), two binary variables GROUP and SUBGROUP and 10 variables Data1 to Data10 in float data format with values < 0.

write outfile = "Outdata.txt"
 /ID (F3.0) GROUP SUBGROUP (2(F2.0)) Data1 to Data10 (10(F4.2)).
Execute.

Should work.

Cheers
Reply | Threaded
Open this post in threaded view
|

Re: Saving data with one space between variables

Maguin, Eugene
In reply to this post by fevziesen
I may be making this more complicated than it actually is but there are three different ways of saving data. One is through the menu for the data window. The second is with the Save Translate command. The third is through the Write command. My impression is that they work differently with respect to inserting a space between values but I may be wrong about that because I always use the write command.

If you use the write command, make sure that the format is one space wider than the widest value.
a) If some variables are numeric, probably the easiest way to do that is to run the data through the descriptives command with statistics=maximum and redefine the format for problem variables. Example. Current format for X1 is f8.2 and widest value is 12345.67. Change to f9.2. Example. Current format for X2 is f8.2 and widest value is 1.23. no change needed. Another way is to write a format statement as part of your write statement, which functionally does the same as using the Format statement.
b) If some variables are string, the easiest way to do this is with the Char.length function followed by, if necessary, the Alter type command. Example. X3 is A4 and widest value is 'abcd'. Have to use Alter type to widen X3. Alter Type X3(a5).

Gene Maguin



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of fevziesen
Sent: Saturday, January 24, 2015 7:28 AM
To: [hidden email]
Subject: Saving data with one space between variables

Hi all,

I need to save my sav file as .txt format but with one space between variables. What do you recommend?



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Saving-data-with-one-space-between-variables-tp5728472.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: Saving data with one space between variables

Jon K Peck
You can use a FORMATS subcommand and specify 1X where you need a blank or just include a blank in the output list

To specify a blank between variables in the output, use a string (see ), specify blank columns in the
format, or use an X or T format element in the WRITE specifications (see DATA LIST for information on X
and T).
Example
WRITE OUTFILE=’/data/personnel.txt’ / TENURE (F2.0) ’ ’ MOHIRED YRHIRED DEPT *
SALARY85 TO SALARY88 (4(DOLLAR8,1X)) NAME.




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




From:        "Maguin, Eugene" <[hidden email]>
To:        [hidden email]
Date:        01/26/2015 10:25 AM
Subject:        Re: [SPSSX-L] Saving data with one space between variables
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




I may be making this more complicated than it actually is but there are three different ways of saving data. One is through the menu for the data window. The second is with the Save Translate command. The third is through the Write command. My impression is that they work differently with respect to inserting a space between values but I may be wrong about that because I always use the write command.

If you use the write command, make sure that the format is one space wider than the widest value.
a) If some variables are numeric, probably the easiest way to do that is to run the data through the descriptives command with statistics=maximum and redefine the format for problem variables. Example. Current format for X1 is f8.2 and widest value is 12345.67. Change to f9.2. Example. Current format for X2 is f8.2 and widest value is 1.23. no change needed. Another way is to write a format statement as part of your write statement, which functionally does the same as using the Format statement.
b) If some variables are string, the easiest way to do this is with the Char.length function followed by, if necessary, the Alter type command. Example. X3 is A4 and widest value is 'abcd'. Have to use Alter type to widen X3. Alter Type X3(a5).

Gene Maguin



-----Original Message-----
From: SPSSX(r) Discussion [
[hidden email]] On Behalf Of fevziesen
Sent: Saturday, January 24, 2015 7:28 AM
To: [hidden email]
Subject: Saving data with one space between variables

Hi all,

I need to save my sav file as .txt format but with one space between variables. What do you recommend?



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Saving-data-with-one-space-between-variables-tp5728472.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


===================== 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: Saving data with one space between variables

Rick Oliver-3
In reply to this post by Andreas Sprenger
save translate /type=csv /textoptions delimiter=" "
  /outfile='<filespec>' /fieldnames /replace.

If you don't want to include variable names at the top, omit the fieldnames subcommand.


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




From:        Andreas Sprenger <[hidden email]>
To:        [hidden email]
Date:        01/26/2015 12:36 PM
Subject:        Re: Saving data with one space between variables
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi,
why not using WRITE. Say you have a variable ID (range 1-99), two binary
variables GROUP and SUBGROUP and 10 variables Data1 to Data10 in float data
format with values < 0.

write outfile = "Outdata.txt"
/ID (F3.0) GROUP SUBGROUP (2(F2.0)) Data1 to Data10 (10(F4.2)).
Execute.

Should work.

Cheers



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Saving-data-with-one-space-between-variables-tp5728478p5728480.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