Macro problem

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

Macro problem

Gyorgy Bea
Dear All,

I have the following macro which gives me error. I want to create as much new variables as many codes I have in v1 to v9, and name the new variables according to these codes. For example if I have codes 1,2,3,4,5, 66,77,99 in v1 to v9, than I want to create vnew_1, vnew_2, vnew_3, vnew_4, vnew_5, vnew_66, vnew_77, vnew_99 with values 1.

DEFINE OES (vars !ENCLOSE('(',')')
        /varname !TOKENS (1)).
         
compute #nr=!vars(all).
vector v=!vars.
compute #i=1.
loop.
do if not missing (v(#i)).
   !let !a=v(#i).
   !let !n=!CONCAT(!varname,"_",!a).
   compute !n=1.
   compute #i=#i+1.
end if.
end loop if #i>#nr.

!ENDDEFINE.

OES vars (v1 to v9)  varname=vnew.



Any suggestion is highly appreciated.

Thanks,
Beata


Reply | Threaded
Open this post in threaded view
|

Re: Macro problem

Gyorgy Bea
Actually I just realized a mistake: it supposed to be Count #nr instead of compute #nr ...

Now it gives this error:

 !let !n=!CONCAT("Q",!varname,v(#i)).
 
>Error # 6839 in column 32.  Text: (
>In a macro expression, a left parenthesis immediately follows an operand.
>This command not executed.


DEFINE OES (vars !ENCLOSE('(',')')
        /varname !TOKENS (1)).
         
count #nr=!vars(0 thru highest, sysmis).
vector v=!vars.
compute #i=1.
loop.
do if not missing (v(#i)).
   !let !n=!CONCAT(!varname,"_",v(#i)).
   compute !n=1.
   compute #i=#i+1.
end if.
end loop if #i>#nr.

!ENDDEFINE.


OES vars (v_63_1 to v_63_27) varname vnew.


Could you please advise?

Many thanks,
Beata



From: Gyorgy Bea <[hidden email]>
To: [hidden email]
Sent: Thursday, April 30, 2009 4:21:33 PM
Subject: Macro problem

Dear All,

I have the following macro which gives me error. I want to create as much new variables as many codes I have in v1 to v9, and name the new variables according to these codes. For example if I have codes 1,2,3,4,5, 66,77,99 in v1 to v9, than I want to create vnew_1, vnew_2, vnew_3, vnew_4, vnew_5, vnew_66, vnew_77, vnew_99 with values 1.

DEFINE OES (vars !ENCLOSE('(',')')
        /varname !TOKENS (1)).
         
compute #nr=!vars(all).
vector v=!vars.
compute #i=1.
loop.
do if not missing (v(#i)).
   !let !a=v(#i).
   !let !n=!CONCAT(!varname,"_",!a).
   compute !n=1.
   compute #i=#i+1.
end if.
end loop if #i>#nr.

!ENDDEFINE.

OES vars (v1 to v9)  varname=vnew.



Any suggestion is highly appreciated.

Thanks,
Beata