Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Conditional INSERT FILE command

36 views
Skip to first unread message

Frank

unread,
Dec 2, 2009, 8:12:22 AM12/2/09
to
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?

Thanks for any suggestions!


Frank Krogh

Rich Ulrich

unread,
Dec 2, 2009, 3:03:30 PM12/2/09
to
On Wed, 2 Dec 2009 05:12:22 -0800 (PST), Frank <fok...@start.no>
wrote:

>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

Art Kendall

unread,
Dec 2, 2009, 3:46:34 PM12/2/09
to
a possible untested workaround would be to cut and paste the conditional
syntax into one insert file.
This presumes that you will want to change the definition of situation.

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

Frank

unread,
Dec 3, 2009, 2:44:05 AM12/3/09
to
Thanks for helping me.

Any suggestion on how to call the macro with a IF test?


Frank

fred....@lsc.gov.uk

unread,
Dec 3, 2009, 10:02:51 AM12/3/09
to
I'm not sure what you are trying to do here.

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'.

Rich Ulrich

unread,
Dec 3, 2009, 5:56:31 PM12/3/09
to
On Wed, 2 Dec 2009 23:44:05 -0800 (PST), Frank <fok...@start.no>
wrote:

>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

0 new messages