Macro Problem

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

Macro Problem

angelina garnica
Hi, I´m new using macro. After a lot of trys I write this code, but it dosen't work.

*////////// PRUEBA_1.
DEFINE !codigos (vnames=!CMDEND)
VECTOR c=v1 TO v5.
VECTOR d=imp_conc1 TO imp_conc5.
!DO !cnt=1 !TO 5
IF (c(!cnt)) = !QUOTE(!vnames).
COMPUTE  !CONCAT('c_', !vnames) = d(!cnt).
!DOEND
!ENDDEFINE.
*//////////.

SET MPRINT = ON.
!codigos vnames = 001_001 001_002 001_003.
(I have more than 100 codes)

The idea is repeat this sintax for all codes.

VECTOR c=v1 TO v5.
VECTOR d=imp_conc1 TO imp_conc5.
LOOP cnt=1 TO 5.
  DO IF (c(cnt)) = '001-001'.
  COMPUTE  c_001_001= d(cnt).
  END IF.
END LOOP.
EXECUTE.

I hope you can help me.

Angelina
Reply | Threaded
Open this post in threaded view
|

Re: Macro Problem

Art Kendall
I only have an impression of what you are trying to do.  Please post a
more detailed description of what you are trying to do and what you are
going to with the resulting variables.
It appears that you have 3 sets of  5  variables  and are trying to get
count of the occurrence of those codes in each set.
If that is correct and that is all you need, it is possible that using
AUTORECODE with the GROUP subcommand follow by MULT RESPONSE will do
what you want.

Art Kendall
Social Research Consultants

angelina garnica wrote:

> Hi, I´m new using macro. After a lot of trys I write this code, but it
> dosen't work.
>
> *////////// PRUEBA_1.
> DEFINE !codigos (vnames=!CMDEND)
> VECTOR c=v1 TO v5.
> VECTOR d=imp_conc1 TO imp_conc5.
> !DO !cnt=1 !TO 5
> IF (c(!cnt)) = !QUOTE(!vnames).
> COMPUTE  !CONCAT('c_', !vnames) = d(!cnt).
> !DOEND
> !ENDDEFINE.
> *//////////.
>
> SET MPRINT = ON.
> !codigos vnames = 001_001 001_002 001_003.
> (I have more than 100 codes)
>
> The idea is repeat this sintax for all codes.
>
> VECTOR c=v1 TO v5.
> VECTOR d=imp_conc1 TO imp_conc5.
> LOOP cnt=1 TO 5.
>   DO IF (c(cnt)) = '001-001'.
>   COMPUTE  c_001_001= d(cnt).
>   END IF.
> END LOOP.
> EXECUTE.
>
> I hope you can help me.
>
> Angelina

=====================
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: Macro Problem

Art Kendall-2
I s this what you want to do?
For each of the  codes  that occur in the set c, find the sum of the values in the set d? b? that have the same index?

b1 goes with v1, b2 does  with v2?

using "d" instead of "b"  is this what you want for a single code that occurs anywhere in set c?
VECTOR c=v1 TO v5.
VECTOR d=imp_conc1 TO imp_conc5.
LOOP cnt=1 TO 5.
 DO IF (c(cnt)) = '001-001'.
 COMPUTE  c_001_001= c_001_001 +d(cnt).
 END IF.
END LOOP.
EXECUTE.

Art Kendall
Social Research Consultants

angelina garnica wrote:
Hallo Art, my problem is more complicated and my english is not so good, I'll try to explain it better

I´ve 2 sets of variables vector c (codes name ej 001_001, 001_002 ...) and vector d (amount of codes)
I need to create a variable c_001_001 .... one for each value of vector c equals to vector b position.

here is an example for 2 variables of my work base

id v1
v2
b1
b2
1 001_001 001_001 727 415
2 001_002 001_008 530
854
3 080_000 000_000 1500 260


The file I need should look like this:

id c_001_001 c_001_002
1 1142
0
2 0 530
3 0 0


The sintaxis work well but i need do it for each code.

well i hope by more clear, thanks

Angelina


On Thu, May 14, 2009 at 11:32 AM, Art Kendall <[hidden email]> wrote:
I only have an impression of what you are trying to do.  Please post a more detailed description of what you are trying to do and what you are going to with the resulting variables.
It appears that you have 3 sets of  5  variables  and are trying to get count of the occurrence of those codes in each set. If that is correct and that is all you need, it is possible that using AUTORECODE with the GROUP subcommand follow by MULT RESPONSE will do what you want.

Art Kendall
Social Research Consultants


angelina garnica wrote:
Hi, I´m new using macro. After a lot of trys I write this code, but it dosen't work.

*////////// PRUEBA_1.
DEFINE !codigos (vnames=!CMDEND)
VECTOR c=v1 TO v5.
VECTOR d=imp_conc1 TO imp_conc5.
!DO !cnt=1 !TO 5
IF (c(!cnt)) = !QUOTE(!vnames).
COMPUTE  !CONCAT('c_', !vnames) = d(!cnt).
!DOEND
!ENDDEFINE.
*//////////.

SET MPRINT = ON.
!codigos vnames = 001_001 001_002 001_003.
(I have more than 100 codes)

The idea is repeat this sintax for all codes.

VECTOR c=v1 TO v5.
VECTOR d=imp_conc1 TO imp_conc5.
LOOP cnt=1 TO 5.
 DO IF (c(cnt)) = '001-001'.
 COMPUTE  c_001_001= d(cnt).
 END IF.
END LOOP.
EXECUTE.

I hope you can help me.

Angelina


Reply | Threaded
Open this post in threaded view
|

Re: Macro Problem

Art Kendall-2
Sorry, I did not see your post until now since it was not in the mailbox I filter the SPSSX-L mail to.  It was in the mailbox for messages from unanticipated senders.

A lot depends on what you are going to do with the resulting variables  if this is something you will not need very often I would not bother with a macro.
If you do not already know the range of codes.
First AUTORECODE the set of variables "c" using the GROUP and PRINT options
then inspect the listing for the actual number of codes found. or the alphabetically maximum code.
If you want only as many variables as there are codes, name the new variables based on the AUTO RECODEd variables.
then wrap the syntax you have in another vector.
something like
 vector  myautocode (77, f8).
Alternatively, you could  copy the list of actually occuring codes from the autorecode and paste them into a syntax window,

or if you want all codes in a range.
numeric c_001_001 to c_001_123 (f8).
 or
vector c_001_001 to c_001_123 (f8).
 
etc.

Alternatively, you could  copy the list of actually occuring codes from the autorecode and paste them into a syntax window,

Art Kendall
Social Research Consultants

angelina garnica wrote:
Yes, that is exact what i want!!
But i have more than 100 codes (001_001) so i was looking for a macro that can do it once.

Thanks
Angelina

On Thu, May 14, 2009 at 6:47 PM, Art Kendall <[hidden email]> wrote:
I s this what you want to do?
For each of the  codes  that occur in the set c, find the sum of the values in the set d? b? that have the same index?

b1 goes with v1, b2 does  with v2?

using "d" instead of "b"  is this what you want for a single code that occurs anywhere in set c?

VECTOR c=v1 TO v5.
VECTOR d=imp_conc1 TO imp_conc5.
LOOP cnt=1 TO 5.
 DO IF (c(cnt)) = '001-001'.
 COMPUTE  c_001_001= c_001_001 +d(cnt).

 END IF.
END LOOP.
EXECUTE.

Art Kendall
Social Research Consultants

angelina garnica wrote:
Hallo Art, my problem is more complicated and my english is not so good, I'll try to explain it better

I´ve 2 sets of variables vector c (codes name ej 001_001, 001_002 ...) and vector d (amount of codes)
I need to create a variable c_001_001 .... one for each value of vector c equals to vector b position.

here is an example for 2 variables of my work base

id v1
v2
b1
b2
1 001_001 001_001 727 415
2 001_002 001_008 530
854
3 080_000 000_000 1500 260


The file I need should look like this:

id c_001_001 c_001_002
1 1142
0
2 0 530
3 0 0


The sintaxis work well but i need do it for each code.

well i hope by more clear, thanks

Angelina


On Thu, May 14, 2009 at 11:32 AM, Art Kendall <[hidden email]> wrote:
I only have an impression of what you are trying to do.  Please post a more detailed description of what you are trying to do and what you are going to with the resulting variables.
It appears that you have 3 sets of  5  variables  and are trying to get count of the occurrence of those codes in each set. If that is correct and that is all you need, it is possible that using AUTORECODE with the GROUP subcommand follow by MULT RESPONSE will do what you want.

Art Kendall
Social Research Consultants


angelina garnica wrote:
Hi, I´m new using macro. After a lot of trys I write this code, but it dosen't work.

*////////// PRUEBA_1.
DEFINE !codigos (vnames=!CMDEND)
VECTOR c=v1 TO v5.
VECTOR d=imp_conc1 TO imp_conc5.
!DO !cnt=1 !TO 5
IF (c(!cnt)) = !QUOTE(!vnames).
COMPUTE  !CONCAT('c_', !vnames) = d(!cnt).
!DOEND
!ENDDEFINE.
*//////////.

SET MPRINT = ON.
!codigos vnames = 001_001 001_002 001_003.
(I have more than 100 codes)

The idea is repeat this sintax for all codes.

VECTOR c=v1 TO v5.
VECTOR d=imp_conc1 TO imp_conc5.
LOOP cnt=1 TO 5.
 DO IF (c(cnt)) = '001-001'.
 COMPUTE  c_001_001= d(cnt).
 END IF.
END LOOP.
EXECUTE.

I hope you can help me.

Angelina