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

Help with macro passing variables

270006NY8W gravatar image
Question by Chris Keran  (26) | Mar 31, 2015 at 03:14 PM spssstatisticsextensibility

I need to run a block of syntax (shown at bottom of this post) for 30 or so variables and I'd prefer to create a macro that passes in each variable rather than create syntax for all 30 variables. Actually, I already created the syntax for all 30 vars, but I'd still prefer to create a macro.

I created part of the macro and was able to get the RANK and sort cases to work, but I got hung up on the "if" statement. It gives me this error which I haven't been able to resolve...

Error # 6834 in column 70. Text: 25

In a macro expression, an operand was not preceded by an operator.

Here is the macro test that I'm getting the error on...

DEFINE !outliers (!POS = !CHAREND('/'))
!DO !i !IN (!1)
RANK VARIABLES=!i (A)
/NTILES(4)
/PERCENT
/PRINT=No
/TIES=MEAN.
sort cases !CONCAT(P,!i) (A).
if (TRUNC(!CONCAT(P,!i)) ge 25 and LAG(!CONCAT(N,!i))=1) !CONCAT(!i,_25th)=!i.
!DOEND
!ENDDEFINE.
!outliers Q16 Q17 Q18 Q19 /.

And here is the syntax that I want turned into a macro, where I would like a macro var to replace all instance of Q16 (which didn't work)...

RANK VARIABLES=Q16 (A)
/NTILES(4)
/PERCENT
/PRINT=No
/TIES=MEAN.
sort cases PQ16 (A).
if (TRUNC(PQ16) ge 25 and LAG(NQ16)=1) Q16_25th=Q16.
if (TRUNC(PQ16) ge 75 and LAG(NQ16)=3) Q16_75th=Q16.
AGGREGATE
/OUTFILE= MODE=ADDVARIABLES
/BREAK=
/Q16_25th_first=FIRST(Q16_25th)
/Q16_75th_first=FIRST(Q16_75th).
compute LOFQ16= Q16_25th_first - 3
(Q16_75th_first - Q16_25th_first).
compute UOFQ16= Q16_75th_first + 3 * (Q16_75th_first - Q16_25th_first).
OMSEND.
temp.
select if Q16 le LOFQ16 or Q16 ge UOFQ16.
freq vars Q16.
Chart Builder.
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=Q16 MISSING=LISTWISE REPORTMISSING=NO
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: Q16=col(source(s), name("Q16"))
DATA: id=col(source(s), name("$CASENUM"), unit.category())
GUIDE: text.title(label("Q16"))
ELEMENT: schema(position(bin.quantile.letter(1*Q16)), label(id))
END GPL.

FYI, this block of syntax identifies outliers (LOF and UOF=Lower and Upper Outer Fences), runs a frequency on those outliers, and then creates a boxplot of all values.

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

5 answers

  • Sort: 
270002VCWN gravatar image

Answer by JonPeck (4671) | Mar 31, 2015 at 05:48 PM

In your if, try quoting the last !CONCAT argument:

!CONCAT(!i,"_25th")=!i.

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
270006NY8W gravatar image

Answer by Chris Keran (26) | Mar 31, 2015 at 06:10 PM

Hah! That was it. Thank you kindly, Jon.

FYI, I knew it was related to "25" but I was incorrectly focusing on the first instance, but after you said it, I saw the error pointed to column 70 in the text--that should've been my clue.

Thanks again.

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
270006NY8W gravatar image

Answer by Chris Keran (26) | Mar 31, 2015 at 06:44 PM

I fixed and ran the entire block and it worked except not the chart. I now get a warning with the GGRAPH command. Thoughts?

 

Warnings

An inline graph specification was expected but not found.

Execution of this command stops.

DEFINE !outliers (!POS = !CHAREND('/'))
!DO !i !IN (!1)
RANK VARIABLES=!i (A)
  /NTILES(4)
  /PERCENT
  /PRINT=No
  /TIES=MEAN.
sort cases  !CONCAT(P,!i) (A).
if (TRUNC(!CONCAT(P,!i)) ge 25 and LAG(!CONCAT(N,!i))=1) !CONCAT(!i,"_25th")=!i.
if (TRUNC(!CONCAT(P,!i)) ge 75 and LAG(!CONCAT(N,!i))=3) !CONCAT(!i,"_75th")=!i.
AGGREGATE
  /OUTFILE= MODE=ADDVARIABLES
  /BREAK=
  /!CONCAT(!i,"_25th_first")=FIRST(!CONCAT(!i,"_25th"))
  /!CONCAT(!i,"_75th_first")=FIRST(!CONCAT(!i,"_75th")).
compute !CONCAT("LOF",!i) = !CONCAT(!i,"_25th_first") - 3
(!CONCAT(!i,"_75th_first") - !CONCAT(!i,"_25th_first")).
compute !CONCAT("UOF",!i) = !CONCAT(!i,"_75th_first") + 3 * (!CONCAT(!i,"_75th_first") - !CONCAT(!i,"_25th_first")).
*OMSEND.
temp.
select if !i le !CONCAT("LOF",!i) or !i ge !CONCAT("UOF",!i).
freq vars !i.

Chart Builder.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=!i MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: !i=col(source(s), name("!i"))
  DATA: id=col(source(s), name("$CASENUM"), unit.category())
  GUIDE: text.title(label("!i"))
  ELEMENT: schema(position(bin.quantile.letter(1
!i)), label(id))
END GPL.
!DOEND
!ENDDEFINE.
 
!outliers Q16 Q17 Q18 Q19 /.

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) | Mar 31, 2015 at 07:02 PM

I'm sorry to have to quote this to you from the CSR:

"Inline GPL blocks cannot be contained within DEFINE-!ENDDEFINE macro definitions. If you want to use
GPL within macro definitions, do not use inline GPL blocks. Put the GPL in a file and reference it with
SOURCE=GPLFILE."

Of course, that solution won't work in your case. While sometimes macro expansion can work in GPL, it is not supported due to the nature of the GPL syntax.

The way to do this is with Python programmability rather than macro. If you want to go that route and can send me some sample data to test with (peck AT us.ibm.com), I can convert this for you.

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
270006NY8W gravatar image

Answer by Chris Keran (26) | Mar 31, 2015 at 08:43 PM

Awesome, thank you. I just now sent you an email.

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

Follow this question

45 people are following this question.

Answers

Answers & comments

Related questions

Installing python plugin 6 Answers

Fuzzy match tolerance 4 Answers

spss.Submit and unicode strings 1 Answer

spssaux.GetValuesFromXMLWorkspace 2 Answers

COM objects only working if SPSS already running? 10 Answers

  • 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