Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Concatenate Numerals from three columns

3,189 views
Skip to first unread message

Manish Madan

unread,
Aug 12, 2011, 5:55:25 PM8/12/11
to
Hi - I tried finding information on the command "Concatenate" and it
is easy to do it when we have string variable. However, let us say I
have 3 columns as follows:

C1 C2 C3
1 4 5

Now, I want to make a new variable that reads '145'. I did as follows:

STRING V501_new (a9).
COMPUTE V501_new = CONCAT(qq01_new, qq02_new, qq04_new).

>Error # 4311 in column 55. Text: )
>The string argument required for the function specified was not supplied.
>Execution of this command stops.
EXECUTE.

any help with correct syntax, please? thanks in advance!

Bruce Weaver

unread,
Aug 12, 2011, 11:11:39 PM8/12/11
to
On 12/08/2011 5:55 PM, Manish Madan wrote:
> Hi - I tried finding information on the command "Concatenate" and it
> is easy to do it when we have string variable. However, let us say I
> have 3 columns as follows:
>
> C1 C2 C3
> 1 4 5
>
> Now, I want to make a new variable that reads '145'. I did as follows:

Are those variables string or numeric? If numeric, and you want a
numeric result, do not use CONCAT. Just do this:

compute newvar = c1*100 + c2*10 + c3.

If that is not what you want, please provide more detail--i.e., what
types of variables are C1-C3, and what type of variable do you want the
result to be.

>
> STRING V501_new (a9).
> COMPUTE V501_new = CONCAT(qq01_new, qq02_new, qq04_new).
>
>> Error # 4311 in column 55. Text: )
>> The string argument required for the function specified was not supplied.
>> Execution of this command stops.
> EXECUTE.
>
> any help with correct syntax, please? thanks in advance!


--
Bruce Weaver
bwe...@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/Home
"When all else fails, RTFM."

MM

unread,
Aug 14, 2011, 10:33:10 PM8/14/11
to
> bwea...@lakeheadu.cahttp://sites.google.com/a/lakeheadu.ca/bweaver/Home

> "When all else fails, RTFM."

Thanks Sir for your help! my variables are numeric. So, when I used
your newvar command, it does that but not exactly what I wanted.

For instance, if I have 1 in C1, missing in C2, C3. I'd hope, newvar
should give me 1 but its gave me 0. Anyhow, I found the fix for that

compute newvar=sum(c1*100,c2*10,c3) instead of using + sign.

thanks again for prompt help!

btw, in the meanwhile I was using another way of doing that (little
more complicated!)

VECTOR v=v1 TO v3.
COMPUTE V3temp=0.
LOOP #cnt=1 TO 3.
IF ~MISSING(v(#cnt))V3temp=V3temp*10 + v(#cnt).
END LOOP.

apparently this also did exactly as concat would do but obviously your
idea was simpler

Message has been deleted

Rich Ulrich

unread,
Aug 15, 2011, 1:57:18 AM8/15/11
to
On Sun, 14 Aug 2011 19:33:50 -0700 (PDT), MM <manish...@gmail.com>
wrote:

>On Aug 12, 11:11�pm, Bruce Weaver <bwea...@lakeheadu.ca> wrote:

>> On 12/08/2011 5:55 PM, Manish Madan wrote:

>[snip, previous]

>Thanks Sir for your help! my variables are numeric. So, when I used
>your newvar command, it does that but not exactly what I wanted.
>
>For instance, if I have 1 in C1, missing in C2, C3. I'd hope, newvar
>should give me 1 but its gave me 0. Anyhow, I found the fix for that

You mean, "should give me 100"

>compute newvar=sum(c1*100,c2*10,c3) instead of using + sign.

I though you would need sum.1( ... ) to avoid the Missing problem;
but if it works, okay.

>
>thanks again for prompt help!
>
>btw, in the meanwhile I was using another way of doing that (little
>more complicated!)
>
>VECTOR v=v1 TO v3.
>COMPUTE V3temp=0.
>LOOP #cnt=1 TO 3.
>IF ~MISSING(v(#cnt))V3temp=V3temp*10 + v(#cnt).
>END LOOP.
>
>apparently this also did exactly as concat would do but obviously your
>idea was simpler

That would also yield "1" instead of "100" when the latter two are
missing. Also be careful and re-check the handling of Missing.

--
Rich Ulrich

Rakesh Kuamr Maurya

unread,
Jun 11, 2014, 1:41:01 AM6/11/14
to
this is the right your function. but

i want to
Concatenating two or more string variables and numeric variables.

Ruben Geert van den Berg

unread,
Jun 11, 2014, 3:39:58 AM6/11/14
to
Hi Rakesh,

Then use CONCAT and convert the numbers into strings with the STRING function.

Also see

http://www.spss-tutorials.com/concatenate/
http://www.spss-tutorials.com/changing-variable-properties-3-type/#stringfunction

0 new messages