f



Help on Concatenation Syntax

Hi,

With the below syntax, i intended to concatenate five string variables (Q1_1 to Q1_5) into a single string variable Q1. 

STRING Q1 (A750).
 COMPUTE Q1=
   CONCAT((STRING(Q1_1)), ",",
          (STRING(Q1_2)), ",",
          (STRING(Q1_3)), ",",
          (STRING(Q1_4)), ",",
          (STRING(Q1_5))).
 EXECUTE.

However, i end up the below error

>Error # 4009 in column 23.  Text: ) 
>The number of arguments to a function was incorrect. 
>Execution of this command stops.

Will appreciate your assistance.

Thanks.
0
Elvis
11/17/2016 5:17:32 PM
comp.soft-sys.stat.spss 5679 articles. 0 followers. Post Follow

4 Replies
487 Views

Similar Articles

[PageSpeed] 29

On Thursday, November 17, 2016 at 12:17:34 PM UTC-5, Elvis Akpabli wrote:
> Hi,
> 
> With the below syntax, i intended to concatenate five string variables (Q1_1 to Q1_5) into a single string variable Q1. 
> 
> STRING Q1 (A750).
>  COMPUTE Q1=
>    CONCAT((STRING(Q1_1)), ",",
>           (STRING(Q1_2)), ",",
>           (STRING(Q1_3)), ",",
>           (STRING(Q1_4)), ",",
>           (STRING(Q1_5))).
>  EXECUTE.
> 
> However, i end up the below error
> 
> >Error # 4009 in column 23.  Text: ) 
> >The number of arguments to a function was incorrect. 
> >Execution of this command stops.
> 
> Will appreciate your assistance.
> 
> Thanks.

From the FM (https://www.ibm.com/support/knowledgecenter/SSLVMB_21.0.0/com.ibm.spss.statistics.help/syn_transformation_expressions_conversion_functions.htm):

STRING. STRING(numexpr,format). String. Returns the string that results when numexpr is converted to a string according to format. STRING(-1.5,F5.2) returns the string value '-1.50'. The second argument format must be a format for writing a numeric value. 

The format is missing in your code.  Try the following, replacing FORMAT with the numeric format you want/need:

CONCAT(STRING(Q1_1,FORMAT), ",",
       STRING(Q1_2,FORMAT), ",",
       STRING(Q1_3,FORMAT), ",",
       STRING(Q1_4,FORMAT), ",",
       STRING(Q1_5,FORMAT)).

HTH.
0
Bruce
11/17/2016 6:19:52 PM
IF Q1_1 to Q1_5 are indeed STRING variables then get rid of the STRING func=
tions altogether.
Something like:

STRING Q1 (A750).
DO REPEAT V=3DQ1_1 to Q1_5.
IF v NE "" Q1=3DCONCAT(RTRIM(Q1),RTRIM(v),",").
END REPEAT.
COMPUTE Q1=3DRTRIM(Q1,",").


On Thursday, November 17, 2016 at 1:19:56 PM UTC-5, Bruce Weaver wrote:
> On Thursday, November 17, 2016 at 12:17:34 PM UTC-5, Elvis Akpabli wrote:
> > Hi,
> >=20
> > With the below syntax, i intended to concatenate five string variables =
(Q1_1 to Q1_5) into a single string variable Q1.=20
> >=20
> > STRING Q1 (A750).
> >  COMPUTE Q1=3D
> >    CONCAT((STRING(Q1_1)), ",",
> >           (STRING(Q1_2)), ",",
> >           (STRING(Q1_3)), ",",
> >           (STRING(Q1_4)), ",",
> >           (STRING(Q1_5))).
> >  EXECUTE.
> >=20
> > However, i end up the below error
> >=20
> > >Error # 4009 in column 23.  Text: )=20
> > >The number of arguments to a function was incorrect.=20
> > >Execution of this command stops.
> >=20
> > Will appreciate your assistance.
> >=20
> > Thanks.
>=20
> From the FM (https://www.ibm.com/support/knowledgecenter/SSLVMB_21.0.0/co=
m.ibm.spss.statistics.help/syn_transformation_expressions_conversion_functi=
ons.htm):
>=20
> STRING. STRING(numexpr,format). String. Returns the string that results w=
hen numexpr is converted to a string according to format. STRING(-1.5,F5.2)=
 returns the string value '-1.50'. The second argument format must be a for=
mat for writing a numeric value.=20
>=20
> The format is missing in your code.  Try the following, replacing FORMAT =
with the numeric format you want/need:
>=20
> CONCAT(STRING(Q1_1,FORMAT), ",",
>        STRING(Q1_2,FORMAT), ",",
>        STRING(Q1_3,FORMAT), ",",
>        STRING(Q1_4,FORMAT), ",",
>        STRING(Q1_5,FORMAT)).
>=20
> HTH.

0
David
11/17/2016 6:57:20 PM
On Thursday, November 17, 2016 at 1:57:25 PM UTC-5, David Marso wrote:
> IF Q1_1 to Q1_5 are indeed STRING variables then get rid of the STRING functions altogether.

Good catch, David.  I jumped straight to the code in the first post, and missed the bit that said the OP "intended to concatenate five string variables".  D'oh!  

> Something like:
> 
> STRING Q1 (A750).
> DO REPEAT V=Q1_1 to Q1_5.
> IF v NE "" Q1=CONCAT(RTRIM(Q1),RTRIM(v),",").
> END REPEAT.
> COMPUTE Q1=RTRIM(Q1,",").

Yes, that looks better (assuming they are string variables to start with).  
0
Bruce
11/17/2016 10:15:25 PM
On Thursday, November 17, 2016 at 10:15:27 PM UTC, Bruce Weaver wrote:
> On Thursday, November 17, 2016 at 1:57:25 PM UTC-5, David Marso wrote:
> > IF Q1_1 to Q1_5 are indeed STRING variables then get rid of the STRING functions altogether.
> 
> Good catch, David.  I jumped straight to the code in the first post, and missed the bit that said the OP "intended to concatenate five string variables".  D'oh!  
> 
> > Something like:
> > 
> > STRING Q1 (A750).
> > DO REPEAT V=Q1_1 to Q1_5.
> > IF v NE "" Q1=CONCAT(RTRIM(Q1),RTRIM(v),",").
> > END REPEAT.
> > COMPUTE Q1=RTRIM(Q1,",").
> 
> Yes, that looks better (assuming they are string variables to start with).

Thanks David and Thanks Bruce.

They are indeed string variables and it did work.

Your support is massively appreciated.

Thanks Again.
0
Elvis
11/18/2016 8:55:44 AM
Reply: