How to pass a string in SPSS macro

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

How to pass a string in SPSS macro

pagudoji
Hi,

I am newbie to this technology. I tried a write a SPSS macro for a set a variables and below is the code.

String Summary(a100).
DEFINE GRAPHIT ( ARG1 !TOKENS(1)/VARF !TOKENS(1)/VARL !TOKENS(1)) .
Do repeat Z=!VARF to !VARL.
compute Summary=concat(rtrim(Summary), string(Z,f10),!ARG1 ).
End repeat.
!ENDDEFINE .

GRAPHIT VARF = VAR1 VARL = VAR4 ARG1=Awarenes of 1st 5 brands.
EXECUTE.

In the above code the ARG1 is a passing variable for a string and it changes everytime. hence based on the variables i need to pass a new string in the 'do repeat'. So when i tried to execute the above code i am getting the following error "Incorrect variable name: either the name is more than 64 characters, or it is not defined by a previous command." so can anyone help me how to pass a constant string in a macro loop.
Reply | Threaded
Open this post in threaded view
|

Re: How to pass a string in SPSS macro

David Marso
Administrator
First off you should describe WHAT you want to achieve with this.
Second, use SET MPRINT ON PRINTBACK ON, rerun the code and post the exact error message.
Maybe simply quoting the string constant might work?
Without some idea of why you want to do this I doubt that happiness follows.

pagudoji wrote
Hi,

I am newbie to this technology. I tried a write a SPSS macro for a set a variables and below is the code.

String Summary(a100).
DEFINE GRAPHIT ( ARG1 !TOKENS(1)/VARF !TOKENS(1)/VARL !TOKENS(1)) .
Do repeat Z=!VARF to !VARL.
compute Summary=concat(rtrim(Summary), string(Z,f10),!ARG1 ).
End repeat.
!ENDDEFINE .

GRAPHIT VARF = VAR1 VARL = VAR4 ARG1=Awarenes of 1st 5 brands.
EXECUTE.

In the above code the ARG1 is a passing variable for a string and it changes everytime. hence based on the variables i need to pass a new string in the 'do repeat'. So when i tried to execute the above code i am getting the following error "Incorrect variable name: either the name is more than 64 characters, or it is not defined by a previous command." so can anyone help me how to pass a constant string in a macro loop.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: How to pass a string in SPSS macro

David Marso
Administrator
I loaded SPSS and ran it with quoted string.
Not sure why this would be in any way useful.
----
DATA LIST FREE / var1 TO var4 (4F1).
BEGIN DATA
1 2 3 4
END DATA.

String Summary(a100).
DEFINE GRAPHIT ( ARG1 !TOKENS(1)/VARF !TOKENS(1)/VARL !TOKENS(1)) .
Do repeat Z=!VARF to !VARL.
compute Summary=concat(rtrim(Summary), string(Z,f10),!ARG1 ).
End repeat.
!ENDDEFINE .

GRAPHIT VARF = VAR1 VARL = VAR4 ARG1='Awareness of 1st 5 brands'.
EXECUTE.
LIST.

var1 var2 var3 var4 Summary
 
  1    2    3    4           1Awareness of 1st 5 brands         2Awareness of 1st 5 brands         3Awareness of 1st 5 b
 
 
Number of cases read:  1    Number of cases listed:  1

David Marso wrote
First off you should describe WHAT you want to achieve with this.
Second, use SET MPRINT ON PRINTBACK ON, rerun the code and post the exact error message.
Maybe simply quoting the string constant might work?
Without some idea of why you want to do this I doubt that happiness follows.

pagudoji wrote
Hi,

I am newbie to this technology. I tried a write a SPSS macro for a set a variables and below is the code.

String Summary(a100).
DEFINE GRAPHIT ( ARG1 !TOKENS(1)/VARF !TOKENS(1)/VARL !TOKENS(1)) .
Do repeat Z=!VARF to !VARL.
compute Summary=concat(rtrim(Summary), string(Z,f10),!ARG1 ).
End repeat.
!ENDDEFINE .

GRAPHIT VARF = VAR1 VARL = VAR4 ARG1=Awarenes of 1st 5 brands.
EXECUTE.

In the above code the ARG1 is a passing variable for a string and it changes everytime. hence based on the variables i need to pass a new string in the 'do repeat'. So when i tried to execute the above code i am getting the following error "Incorrect variable name: either the name is more than 64 characters, or it is not defined by a previous command." so can anyone help me how to pass a constant string in a macro loop.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: How to pass a string in SPSS macro

Rich Ulrich
My Internet-esp hints that what he wants is a print statement,

PRINT outfile= [whatever] / "Awareness of first 5 brands"  V1 to V5 (5F10).

> Date: Mon, 18 Jan 2016 11:18:21 -0700
> From: [hidden email]
> Subject: Re: How to pass a string in SPSS macro
> To: [hidden email]
>
> I loaded SPSS and ran it with quoted string.
> Not sure why this would be in any way useful.

--
Rich Ulrich
===================== 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: How to pass a string in SPSS macro

John F Hall

Could also try?

(not available from GUI):

 

Subtitle ‘Awareness of first 5 brands ’.

<analysis>

 

John F Hall (Mr)

[Retired academic survey researcher]

 

Email:   [hidden email] 

Website: www.surveyresearch.weebly.com

SPSS start page:  www.surveyresearch.weebly.com/1-survey-analysis-workshop

 

 

 

 

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Rich Ulrich
Sent: 18 January 2016 21:08
To: [hidden email]
Subject: Re: How to pass a string in SPSS macro

 

My Internet-esp hints that what he wants is a print statement,

PRINT outfile= [whatever] / "Awareness of first 5 brands"  V1 to V5 (5F10).

> Date: Mon, 18 Jan 2016 11:18:21 -0700
> From: [hidden email]
> Subject: Re: How to pass a string in SPSS macro
> To: [hidden email]
>
> I loaded SPSS and ran it with quoted string.
> Not sure why this would be in any way useful.

--
Rich Ulrich

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