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

SPSS list variables if a certain condition occurs

2,608 views
Skip to first unread message

Marcia

unread,
Apr 29, 2010, 10:07:23 PM4/29/10
to carlos...@yahoo.com
I am new to SPSS and I have a question:

I would like to list variables VAR1 and VAR2 only if FLAG=1.

LIST VAR1 VAR2. ==> will list these variables for all values of
FLAG.

So how can I do this?

thanks

SFC

unread,
Apr 29, 2010, 10:58:51 PM4/29/10
to

How about these commands?

Recode Flag (1=1) (else=0) into filter_$.
Filter by filter_$.
List Var1 Var2.
Filter off.

You can recode another value to 1.

--
Shu Fai

Marcia

unread,
Apr 29, 2010, 11:08:37 PM4/29/10
to

Hi Shu.

I used your code and I think it's woking fine.
It lists VAR1 and VAR2 only when Flag=1, right?
It is not listing anything and I think it's because all values for
FLAG are different than one.

Thanks for your help.

SFC

unread,
Apr 29, 2010, 11:38:10 PM4/29/10
to

You can double-check the syntax by changing 1 to another value which
you know exists in the dataset for FLAG, and see whether some cases
are listed. I also nearly always double-check my syntax. I made
mistakes occasionally in the first version. :)

--
Shu Fai

Marcia

unread,
Apr 29, 2010, 11:51:17 PM4/29/10
to

Hi Shu.

Yes, I forced FLAG to be equal to one and all cases are listed now.

Thanks a lot again,
M

Bruce Weaver

unread,
Apr 30, 2010, 7:11:14 AM4/30/10
to
On Apr 29, 10:58 pm, SFC <shufai.che...@gmail.com> wrote:

If you're only doing one thing with the filter in place, a TEMPORARY
SELECT IF works well with less code, and no need to compute a new
filter variable.

temporary.
select if (FLAG EQ 1).
list var1 var2 .


--
Bruce Weaver
bwe...@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/Home
"When all else fails, RTFM."

Marcia

unread,
Apr 30, 2010, 7:39:31 AM4/30/10
to
> bwea...@lakeheadu.cahttp://sites.google.com/a/lakeheadu.ca/bweaver/Home

> "When all else fails, RTFM."

thanks Shu, I will try that too.

SFC

unread,
Apr 30, 2010, 2:10:28 PM4/30/10
to
> bwea...@lakeheadu.cahttp://sites.google.com/a/lakeheadu.ca/bweaver/Home

> "When all else fails, RTFM."

Thanks for this version.

Marcia, note Bruce's remark ("only doing one thing ..."), which is
important. This version works only for the first command after SELECT
IF that reads data, i.e., the LIST command in this case. In the
version using FILTER, you can include more than one command between
the FILTER BY ... FILTER OFF block, e.g., several LIST commands, or
LIST and DESCRIPTIVE, etc.

Nevertheless, if I am pretty sure all I need is temporary filtering
for one command, I would use Bruce's version too. Simple and clear. I
personally use FILTER more because I may have some other commands to
add later for the filtered group.

--
Shu Fai

David

unread,
May 1, 2010, 2:17:33 PM5/1/10
to

DO IF (Condion).
PRINT / varlist . /*PRINT is a transformation */
END IF.
EXE (or another procedure).

Carlos Arieira

unread,
May 3, 2010, 3:11:35 PM5/3/10
to
On Apr 30, 7:11 am, Bruce Weaver <bwea...@lakeheadu.ca> wrote:
> bwea...@lakeheadu.cahttp://sites.google.com/a/lakeheadu.ca/bweaver/Home
> "When all else fails, RTFM."- Hide quoted text -
>
> - Show quoted text -

Thanks Bruce.
Sorry, I read this quickly and thought it was still Shu responding.

Yes, your suggestion works too.

Thanks again.

Carlos Arieira

unread,
May 3, 2010, 3:13:17 PM5/3/10
to

I tried this before but with LIST instead of PRINT and it didn't work.
I will try what you suggest too.
Thanks David.

0 new messages