Syntax for creating a third variable

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

Syntax for creating a third variable

E. Bernardo
Hi SPSS users,
 
Resending the relevant but neglected post a couple of days..
 
I have two variables X and Y, where X have no missing values while Y have many missing values.  I want to create a third variable Z whose values are the values of Y and the missing values of Y are replace with the values of X.  The data structure looks like below:
 
X     Y        Z
a     f         f
b              b
c     g       g
d              d
e              e
 
Do you know of a syntax to create Z? 
 
Thank you.
Eins


HOTMAIL, GMAIL, ….ACCOUNTS?
Invite your friends from Hotmail, Gmail to Yahoo! Messenger today!
Reply | Threaded
Open this post in threaded view
|

Re: Syntax for creating a third variable

Keith Jackman

Eins,
 
I would set Z equal to X and then reassign to Y if Y exists. 
 
So...
 
STRING z (A8).
COMPUTE z=x.
IF (Y>"") z=y.
 
Keith
 
----- Original Message -----
Sent: Wednesday, March 18, 2009 10:17 PM
Subject: Syntax for creating a third variable

Hi SPSS users,
 
Resending the relevant but neglected post a couple of days..
 
I have two variables X and Y, where X have no missing values while Y have many missing values.  I want to create a third variable Z whose values are the values of Y and the missing values of Y are replace with the values of X.  The data structure looks like below:
 
X     Y        Z
a     f         f
b              b
c     g       g
d              d
e              e
 
Do you know of a syntax to create Z? 
 
Thank you.
Eins


HOTMAIL, GMAIL, ….ACCOUNTS?
Invite your friends from Hotmail, Gmail to Yahoo! Messenger today!
Reply | Threaded
Open this post in threaded view
|

Re: Syntax for creating a third variable

Art Kendall
In reply to this post by E. Bernardo
Open a new instance of SPSS.  Copy the syntax below to a syntax file.
Click <run>. Click <all>.
is this what you are looking for?


data list list/ X     Y        Want (3a1).
begin data
a     f         f
b     ''         b
c     g       g
d     ''         d
e      ''        e
end data.
list.
string z (a1).
compute z=y.
if y eq '' z=x.
LIST .

Art Kendall
Social Research Consultants

Eins Bernardo wrote:

> Hi SPSS users,
>
> Resending the relevant but neglected post a couple of days..
>
> I have two variables X and Y, where X have no missing values while Y
> have many missing values.  I want to create a third variable Z whose
> values are the values of Y and the missing values of Y are replace
> with the values of X.  The data structure looks like below:
>
> X     Y        Z
> a     f         f
> b              b
> c     g       g
> d              d
> e              e
>
> Do you know of a syntax to create Z?
>
> Thank you.
> Eins
>
>
> ------------------------------------------------------------------------
> HOTMAIL, GMAIL, ….ACCOUNTS?
> <http://sg.rd.yahoo.com/ph/mail/trueswitch/mailtagline/*http://www.trueswitch.com/yahoo-ph/>
> Invite your friends from Hotmail, Gmail to Yahoo! Messenger today!

=====================
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Syntax for creating a third variable

Guerrero, Rodrigo
In reply to this post by E. Bernardo

Try this.

 

COMPUTE X=Z.

IF  (MISSING(Y)) Z=Y.

EXECUTE.

 

 

RG

 

Rodrigo A. Guerrero | Director Of Marketing Research and Analysis | The Scooter Store | 830.627.4317

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Eins Bernardo
Sent: Thursday, March 19, 2009 12:18 AM
To: [hidden email]
Subject: Syntax for creating a third variable

 

Hi SPSS users,

 

Resending the relevant but neglected post a couple of days..

 

I have two variables X and Y, where X have no missing values while Y have many missing values.  I want to create a third variable Z whose values are the values of Y and the missing values of Y are replace with the values of X.  The data structure looks like below:

 

X     Y        Z

a     f         f

b              b

c     g       g

d              d

e              e

 

Do you know of a syntax to create Z? 

 

Thank you.

Eins

 


HOTMAIL, GMAIL, ….ACCOUNTS?
Invite your friends from Hotmail, Gmail to Yahoo! Messenger today!


The information transmitted is intended only for the addressee(s) and may contain confidential or privileged material, or both. Any review, receipt, dissemination or other use of this information by non-addressees is prohibited. If you received this in error or are a non-addressee, please contact the sender and delete the transmitted information.
Reply | Threaded
Open this post in threaded view
|

Re: Syntax for creating a third variable

statisticsdoc
In reply to this post by E. Bernardo

Eins,
 
I see that you have received a number of good responses for this question as it pertains to the example you gave, which has alphanumeric data.  Should you ever need to apply a similar procedure with numeric data, use:
 
if (NOT MISSING(y)) z = y .

if (missing(y) ) z = x .

exe .

Best,

Stephen Brand

 

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Eins Bernardo
Sent: Thursday, March 19, 2009 1:18 AM
To: [hidden email]
Subject: Syntax for creating a third variable

Hi SPSS users,
 
Resending the relevant but neglected post a couple of days..
 
I have two variables X and Y, where X have no missing values while Y have many missing values.  I want to create a third variable Z whose values are the values of Y and the missing values of Y are replace with the values of X.  The data structure looks like below:
 
X     Y        Z
a     f         f
b              b
c     g       g
d              d
e              e
 
Do you know of a syntax to create Z? 
 
Thank you.
Eins