FREQ var1.
DO IF var1 = ('4702').
INSERT FILE 'c:\syntax4702.sps'.
END IF.
DO IF var1 = ('4703').
INSERT FILE 'c:\syntax4703.sps'.
END IF.
Is it possible to use macro DEFINE-ENDDEFINE to perform a conditonal
execution of a INSERT FILE command?
Thanks for any suggestions!
Frank Krogh
>I want to execute a conditional INSERT FILE command like this.
>
>FREQ var1.
>DO IF var1 = ('4702').
>INSERT FILE 'c:\syntax4702.sps'.
>END IF.
>DO IF var1 = ('4703').
>INSERT FILE 'c:\syntax4703.sps'.
>END IF.
>
>Is it possible to use macro DEFINE-ENDDEFINE to perform a conditonal
>execution of a INSERT FILE command?
Someone could correct me if I have it wrong, but
I expect that INSERT is performed when it is encountered,
at an earlier stage of parsing than IF.
If that is so, then the above won't work, but it is easy
to fix. I think.
Namely - define a couple of macros for 4702 and 4703,
where there is a macro name/end surrounding the
INSERT FILE statement. The macro will consist of just
the inserted lines.
Then, call the appropriate macro as a condition of IF,
instead of trying to do INSERT.
--
Rich Ulrich
numeric situation (f1).
recode var1 ('4702' = 1)('4703' =2)(ELSE=3) INTO situation.
INSERT FILE 'c:\situationsyntax.sps'.
situationsyntax.sps contains something like
do if situation eq 1.
*cut and paste the syntax that used to be 'c:\syntax4702.sps' here.
else if situation eq 2.
*cut and paste the syntax that used to be 'c:\syntax4703.sps' here.
else.
end if.
If you always want to have those two values define the condition
something like this in the INSERT file.
situationsyntax.sps contains something like
DO IF var1 = ('4702').
*cut and paste the syntax that used to be 'c:\syntax4702.sps' here.
ELSE IF var1 = ('4703').
*cut and paste the syntax that used to be 'c:\syntax4703.sps' here.
else.
end if.
Art Kendall
Social Research Consultants
Any suggestion on how to call the macro with a IF test?
Frank
You can't do what you want to do, and It's not really logical to
insert a file on an if command. For example if your insert command was
a get file, then you couldn't do it on specific cases.
If you want to run specific commands on a subset of the data the
rather than use a do if, you want to look at whether a select command
would be more appropriate
E.g.
get fil -----
select IF var1 = ('4702').
INSERT FILE 'c:\syntax4702.sps'.
get fil -----
select IF var1 = ('4703').
INSERT FILE 'c:\syntax4702.sps'.
You could wrap it all up in a macro along the lines of
define !Selsyn (!pos !CMDEND ('/')).
!do !i !in (!1).
get fil ='................'
select IF var1 = !i.
INSERT FILE =!Quote(!concat(!Unquote('c:\syntax'), !unquote(!i), !
Unquote('.sps'))).
!doend.
!Enddefine.
!Selsyn '4702' '4703'.
>Thanks for helping me.
>
>Any suggestion on how to call the macro with a IF test?
>
put it where you had your INSERT.
--
Rich Ulrich