Digital Developer Conference: a FREE half-day online conference focused on AI & Cloud – North America: Nov 2 – India: Nov 9 – Europe: Nov 14 – Asia Nov 23 Register now

Close outline
  • United States
IBM?
  • Site map
IBM?
  • Marketplace

  • Close
    Search
  • Sign in
    • Sign in
    • Register
  • IBM Navigation
IBM Developer Answers
  • Spaces
    • Blockchain
    • IBM Cloud platform
    • Internet of Things
    • Predictive Analytics
    • Watson
    • See all spaces
  • Tags
  • Users
  • Badges
  • FAQ
  • Help
Close

Name

Community

  • Learn
  • Develop
  • Connect

Discover IBM

  • ConnectMarketplace
  • Products
  • Services
  • Industries
  • Careers
  • Partners
  • Support
10.190.13.195

Refine your search by using the following advanced search options.

Criteria Usage
Questions with keyword1 or keyword2 keyword1 keyword2
Questions with a mandatory word, e.g. keyword2 keyword1 +keyword2
Questions excluding a word, e.g. keyword2 keyword1 -keyword2
Questions with keyword(s) and a specific tag keyword1 [tag1]
Questions with keyword(s) and either of two or more specific tags keyword1 [tag1] [tag2]
To search for all posts by a user or all posts with a specific tag, start typing and choose from the suggestion list. Do not use a plus or minus sign with a tag, e.g., +[tag1].
  • Ask a question

conditional aggregation

270003VM8T gravatar image
Question by redrose888  (0) | Jul 02, 2013 at 12:51 PM spssstatisticssyntax

Dear all,

I would run the followong syntax:

compute t = 0.

loop if (sysmis(myvar)).

AGGREGATE
/OUTFILE=* MODE = ADDVARIABLES OVERWRITE = YES
/BREAK=t
/myvar = SUM(var).

end loop.

but I got error messagen, is there any other method to solve this problem?

thanks!

People who like this

  0
Comment
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster

13 answers

  • Sort: 
270002VCWN gravatar image

Answer by JonPeck (4671) | Jul 03, 2013 at 01:36 AM

What is it you are trying to accomplish here? AGGREGATE operates on an entire dataset while loop operates on the values in a case, so the two don't go together.

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
270003VM8T gravatar image

Answer by redrose888 (0) | Jul 03, 2013 at 06:30 AM

Hello Jon,

I want to run a block of syntax so many times, till a certain variable becomes sysmiss. In this block are some compute, aggregate and match files commands

something like this:

while (~sysmis(myvar)) insert "C:\temp\block.sps"

whether one can via Python do it?

thanks!

baiyun

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
270002VCWN gravatar image

Answer by JonPeck (4671) | Jul 03, 2013 at 12:50 PM

Are you saying that you want to run this insert code if any case has a sysmis value for myvar or if all the values are sysmis or if a certain case has a sysmis value? The sysmis test will run on a per-case value, but you can't execute, say, an AGGREGATE command in the middle of passing the cases, since AGGREGATE works on the whole dataset.

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
270003VM8T gravatar image

Answer by redrose888 (0) | Jul 03, 2013 at 12:58 PM

yes, if any case has a sysmis value for myvar

at the beginning myvar has some valid value, after do block.sps many times, myvar becomes sysmis

i could do this with a macro, like

DEFINE !doit(loopnr = !cmdend)

!DO !cnt=1 !TO !loopnr

!repeat

!DOEND

!ENDDEFINE.

!doit loopnr = 3.

but i have to check output everytime, I want to do this automatically.

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
270002VCWN gravatar image

Answer by JonPeck (4671) | Jul 03, 2013 at 01:17 PM

Here is an example of how you might do this. Annotations below.

compute z = $sysmis.
begin program.
import spss
while True:
curs = spss.Cursor([10])
values = curs.fetchall()
curs.close()
if not (None,) in values:
break
spss.Submit("""compute z = rv.uniform(0,1).""")
end program.

z is the 11th variable in this dataset. First it gets a cursor object and reads all the values for index 10 (zero based).
If any value is None, i.e., sysmis, it Submits some syntax, which could be an insert command, and repeats the process.

Since fetchall returns a tuple containing one element for each case because of the definition of this cursor, the test is whether a tuple with one element, i.e. (None,) , is in any of the cases.

HTH,

Jon

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
270003VM8T gravatar image

Answer by redrose888 (0) | Jul 03, 2013 at 01:41 PM

thanks Jon!

you wrote :

If any value is None, i.e., sysmis, it Submits some syntax

block.sps should run till myvar becomes sysmis completely

I ran

get file = "C:\temp\test.sav".

begin program.
import spss
while True:
curs = spss.Cursor([12])
values = curs.fetchall()
curs.close()
if not (None,) in values:
break
spss.Submit("INSERT FILE='c:/temp/block.sps'.")
end program.

spss runs non-stop?

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
270002VCWN gravatar image

Answer by JonPeck (4671) | Jul 03, 2013 at 02:17 PM

That loop will run until there are no sysmis values. You might want to insert a DESCRIPTIVES command to see what is happening to the test variable, or just run the loop once and look in the DE.

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
270003VM8T gravatar image

Answer by redrose888 (0) | Jul 03, 2013 at 02:28 PM

I understand now why spss ran non-stop! what I want is the reverse direction!

i want: That loop will run until there are only sysmis values!

should I write if (None,) in values: instead if not (None,) ?

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
270002VCWN gravatar image

Answer by JonPeck (4671) | Jul 03, 2013 at 02:41 PM

yes

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
270003VM8T gravatar image

Answer by redrose888 (0) | Jul 04, 2013 at 10:03 AM

Hello Jon

i let the following lines run:

get file = "C:\temp\test1.sav".


begin program.
import spss
while True:
curs = spss.Cursor([12])
values = curs.fetchall()
print values
curs.close()
if (None,) in values:
print 'ok1'

break

else:
print 'ok'
spss.Submit("INSERT FILE='c:/temp/block.sps'.")
end program.

in the output :

((12.85061,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,))

ok1

it is strange, ok didn't appear, although 12.85061 isn't a None

block.sps didn't be run too.

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • 1
  • 2
  • ›

Follow this question

46 people are following this question.

Answers

Answers & comments

Related questions

Recoding Multiple String Variables Into One 3 Answers

May someone help me to solve a problem with running the conjoint analysis syntax? 1 Answer

SPSS RAKE error message 7 Answers

IF statement with a date variable 1 Answer

How to Count No of Variables in a SPSS Data File 1 Answer

  • Contact
  • Privacy
  • IBM Developer Terms of use
  • Accessibility
  • Report Abuse
  • Cookie Preferences

Powered by AnswerHub

Authentication check. Please ignore.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • API Connect
  • Analytic Hybrid Cloud Core
  • Application Performance Management
  • Appsecdev
  • BPM
  • Blockchain
  • Business Transaction Intelligence
  • CAPI
  • CAPI SNAP
  • CICS
  • Cloud Analytics
  • Cloud Automation
  • Cloud Object Storage
  • Cloud marketplace
  • Collaboration
  • Content Services (ECM)
  • Continuous Testing
  • Courses
  • Customer Experience Analytics
  • DB2 LUW
  • Data and AI
  • DataPower
  • Decision Optimization
  • DevOps Build
  • DevOps Services
  • Developers IBM MX
  • Digital Commerce
  • Digital Experience
  • Finance
  • Global Entrepreneur Program
  • Hadoop
  • Hybrid Cloud Core
  • Hyper Protect
  • IBM Cloud platform
  • IBM Design
  • IBM Forms Experience Builder
  • IBM Maximo Developer
  • IBM StoredIQ
  • IBM StoredIQ-Cartridges
  • IIDR
  • ITOA
  • InformationServer
  • Integration Bus
  • Internet of Things
  • Kenexa
  • Linux on Power
  • LinuxONE
  • MDM
  • Mainframe
  • Messaging
  • Node.js
  • ODM
  • Open
  • PartnerWorld Developer Support
  • PowerAI
  • PowerVC
  • Predictive Analytics
  • Product Insights
  • PureData for Analytics
  • Push
  • QRadar App Development
  • Run Book Automation
  • Search Insights
  • Security Core
  • Storage
  • Storage Core
  • Streamsdev
  • Supply Chain Business Network
  • Supply Chain Insights
  • Swift
  • UBX Capture
  • Universal Behavior Exchange
  • UrbanCode
  • WASdev
  • WSRR
  • Watson
  • Watson Campaign Automation
  • Watson Content Hub
  • Watson Marketing Insights
  • dW Answers Help
  • dW Premium
  • developerWorks Sandbox
  • developerWorks Team
  • Watson Health
  • More
  • Tags
  • Questions
  • Users
  • Badges