Problem with using a PARAMETER

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

Problem with using a PARAMETER

Boika Mileva
Dear colleagues!

I am using SPSS 15 and I have the following problem trying to use a
parameter in order to keep variables with different names depending on the
year of the output data: I define the parameter in the following way:

DEFINE !Year()
“08”
!ENDDEFINE.

WHERE: “08” means, that the year is 2008.

Further on in the syntax, I have to write:

SAVE OUTFILE=!path+'TEMP_Data\IndDATA.sav'
KEEP NACE03 I08_01 I08_02 /COMPRESSED.

Everything is OK with this command, but when I try to replace 08 with my
parameter (!Year) in the following way:

SAVE OUTFILE=!path+'TEMP_Data\IndDATA.sav'
KEEP NACE03 "I" + !Year + "_01" + " I" + !Year + "_02" /COMPRESSED.

I get the following error message:

Error # 5242 in column 13.  Text: I00_01 I00_02
>Unexpected or invalid symbol in a variable list.
>This command not executed.

Obviously there is something wrong in my command. I would be grateful if
some of you suggests me how to solve my problem.

THANK YOU IN ADVANCE!

With best wishes:

Boika Mileva

=====================
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: Problem with using a PARAMETER

Albert-Jan Roskam
So you want to save three vars, which have (at least in 2008) the following names: NACE03 I08_01 I08_02. I never use string concatenation in the way you describe. But I think you just used one plus-sign too many, and you also omitted a forward slash:
SAVE OUTFILE=!path + 'TEMP_Data\IndDATA.sav'
  / KEEP = NACE03
   "I" + !Year + "_01"
   "I" + !Year + "_02"
   /COMPRESSED.
If you use the code inside a macro, you should enclose all macros in !eval(!macroname).

Cheers!!
Albert-Jan


--- On Wed, 11/19/08, Boika Mileva <[hidden email]> wrote:

> From: Boika Mileva <[hidden email]>
> Subject: Problem with using a PARAMETER
> To: [hidden email]
> Date: Wednesday, November 19, 2008, 10:44 AM
> Dear colleagues!
>
> I am using SPSS 15 and I have the following problem trying
> to use a
> parameter in order to keep variables with different names
> depending on the
> year of the output data: I define the parameter in the
> following way:
>
> DEFINE !Year()
> “08”
> !ENDDEFINE.
>
> WHERE: “08” means, that the year is 2008.
>
> Further on in the syntax, I have to write:
>
> SAVE OUTFILE=!path+'TEMP_Data\IndDATA.sav'
> KEEP NACE03 I08_01 I08_02 /COMPRESSED.
>
> Everything is OK with this command, but when I try to
> replace 08 with my
> parameter (!Year) in the following way:
>
> SAVE OUTFILE=!path+'TEMP_Data\IndDATA.sav'
> KEEP NACE03 "I" + !Year + "_01" +
> " I" + !Year + "_02" /COMPRESSED.
>
> I get the following error message:
>
> Error # 5242 in column 13.  Text: I00_01 I00_02
> >Unexpected or invalid symbol in a variable list.
> >This command not executed.
>
> Obviously there is something wrong in my command. I would
> be grateful if
> some of you suggests me how to solve my problem.
>
> THANK YOU IN ADVANCE!
>
> With best wishes:
>
> Boika Mileva
>
> =====================
> 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: Problem with using a PARAMETER

Boika Mileva
In reply to this post by Boika Mileva
Dear Albert!

Thank you for your reply! Unfortunately, with your suggestion, I received
a similar result:

>Error # 5242 in column 2.  Text: I08_01
>Unexpected or invalid symbol in a variable list.
>This command not executed.


>Error # 5242 in column 2.  Text: I08_02
>Unexpected or invalid symbol in a variable list.

Obviously, the "combined" strings are just as the respective names of the
variables are, but SPSS expects name, not string. Probably the approach
should be different...

=====================
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: Problem with using a PARAMETER

Frans Marcelissen-2
Hi Boike.
You are correct, you can not mix string functions with strings in a var
list. A var list should, as far as I know, be a literal string (or a macro,
because the macro is evaluated before the procedure is called.)
The solution is to use an extra define:

----
DEFINE !Year()
1
!ENDDEFINE.

DEFINE !varnames(year = !TOKENS(1))
!CONCAT("I",!year,"_01") !CONCAT("I",!year,"_02")
!ENDDEFINE


SAVE OUTFILE='c:\TEMP\IndDATA.sav'
  / KEEP = !varnames year =  !Year
 /COMPRESSED.
----
(I tried this and did not get an error message)
With kind regards

-------------------------------------------
Frans Marcelissen
tel 06 2325 0652
email [hidden email]
-----Oorspronkelijk bericht-----
Van: SPSSX(r) Discussion [mailto:[hidden email]] Namens Boika
Mileva
Verzonden: woensdag 19 november 2008 14:06
Aan: [hidden email]
Onderwerp: Re: Problem with using a PARAMETER

Dear Albert!

Thank you for your reply! Unfortunately, with your suggestion, I received
a similar result:

>Error # 5242 in column 2.  Text: I08_01
>Unexpected or invalid symbol in a variable list.
>This command not executed.


>Error # 5242 in column 2.  Text: I08_02
>Unexpected or invalid symbol in a variable list.

Obviously, the "combined" strings are just as the respective names of the
variables are, but SPSS expects name, not string. Probably the approach
should be different...

=====================
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: Problem with using a PARAMETER

Boika Mileva
In reply to this post by Boika Mileva
Hi Frans!

Thank you for the GREAT IDEA! Here is the whole part of the syntax, based
on your idea and IT WORKS PERFECTLY!
*========================================================================.
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%.
DEFINE !Year()
02
!ENDDEFINE.

DEFINE !varnames(year = !TOKENS(1))
!CONCAT("I",!year,"_01") !CONCAT("I",!year,"_02") !CONCAT("I",!year,"_03")
!CONCAT("I",!year,"_04") !CONCAT("I",!year,"_05") !CONCAT("I",!year,"_06")
!CONCAT("I",!year,"_07") !CONCAT("I",!year,"_08") !CONCAT("I",!year,"_09")
!CONCAT("I",!year,"_10") !CONCAT("I",!year,"_11") !CONCAT("I",!year,"_12")
!ENDDEFINE.

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%.

SAVE OUTFILE=!path+'TEMP_Data\IndDATA.sav'
  / KEEP = NACE03 !varnames year = !Year
 /COMPRESSED.

*========================================================================.

Thank you once more time!

With best wishes!

Boika

=====================
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