[vsni.co.uk] Contact us
Author Message
Post new topic

  GenStat  ~  Procedure parameter question

AndrewMc
Posted: Sun Jun 24, 2018 9:48 pm Reply with quote
Joined: 28 Jul 2008 Posts: 76
Hi All

I am working on a procedure that takes as input either a list of variates or a single variate with a grouping factor. I have gotten this working (largely by borrowing code from the KRUSKAL procedure) but have come unstuck when I have tried to add a LABELS parameter for an output text that will contain a list of either the variate names or the group factor levels/labels. I have included some cut-down procedure code with some test code below.
Of particular note is the initial PROCEDURE statement which includes "PARAMETER=pointer" so as to allow using the list of DATA variants altogether at once. This means that the LABELS parameter is also a pointer which may be what is tripping me up. In addition, I have noticed that even when I don't use the LABELS parameter, the SET(LABELS) statement evaluates to true which I wasn't expecting.

Does anyone have any advice or suggestions as to how I could get the LABELS saving correctly? I have other output that I want to save in additional parameters but figure that getting the LABELS to save would be a great start.

Cheers,
Andrew Mc

"=================================================================="
PROCEDURE [PARAMETER=pointer; WORDLENGTH=long] 'AAAA'
OPTION 'GROUPS'; " (I: factor) defines groups " \
MODE=p; NVALUES=*; VALUES=*; DEFAULT=*; \
SET=no; DECLARED=no; LIST=no; TYPE='factor'; PRESENT=no
PARAMETER 'DATA', " (I: variate) data " \
'LABELS'; " (O: text) labels for the DATA groups"\
MODE = P,P; SET = yes,no; DECLARED = yes,no; \
TYPE = 'variate','text'; PRESENT = yes,no; INPUT = yes,no
CALLS GETNAME

IF (NVAL(DATA).EQ.1)
FAULT [EXPLANATION=\
'GROUPS option must be set if only one variate is specified.']\
UNSET(GROUPS)
GETATTRIBUTE [ATTRIBUTE=nlevels,levels,labels] GROUPS; SAVE=gatt
& [ATTRIBUTE=stype] gatt['labels']; SAVE=!p(stemp)
IF stemp.EQS.'text'
TEXT gname; VALUES=!t(#gatt['labels'])
ELSE
TXCONSTR [TEXT=gname] gatt['levels']
ENDIF
ELSE "(NVAL(DATA).NE.1)"
CALCULATE NDAT = NVAL(DATA)
GETNAME DATA[1...NDAT]; NAME=vname[1...NDAT]
TEXT gname; VALUES=!t(#vname[1...NDAT])
ENDIF "(NVAL(DATA).EQ.1)"

IF SET(LABELS)
caption 'LABELS set!!!'; note
print [SQ=y] nval(LABELS); deci=0
getattr [attr=stype] LABELS; SAVE=aLab
print aLab[]
\print gname
IF (NVAL(DATA).EQ.1)
TEXT LABELS; VALUE=gname
ELSE
TEXT LABELS; VALUE=gname
ENDIF
ELSE
caption 'LABELS not set'; note
ENDIF

ENDPROCEDURE

"Create test data"
delete [r=y] SiteI,SiteII,SiteIII,SiteIV,Site,Data
variate SiteI,SiteII,SiteIII,SiteIV; va=!(46,28,46,37,32,41,42,45,38,44),\
!(42,60,32,42,45,58,27,51,42,52),!(38,33,26,25,28,28,26,27,27,27),\
!(31,30,27,29,30,25,25,24,27,30)
stack [Site] Data; V1=!p(SiteI,SiteII,SiteIII,SiteIV)

"Test example with multiple DATA variates"
caption 'Multiple DATA variates, LABELS ~b{NOT} set'; stress
AAAA SiteI,SiteII,SiteIII,SiteIV
caption 'Multiple DATA variates, LABELS set'; stress
delete [r=y] txLab
AAAA SiteI,SiteII,SiteIII,SiteIV; LABEL=txLab
print txLab
AAAA SiteI,SiteII,SiteIII,SiteIV; LABEL=txLab
print txLab

"Test example with a single DATA variate plus a GROUPS factor"
caption 'Single DATA variate, LABELS ~b{NOT} set'; stress
AAAA [GROUP=Site] Data
caption 'Single DATA variate, LABELS set'; stress
delete [r=y] txLab
AAAA [GROUP=Site] Data; LABEL=txLab
"=================================================================="

Andrew McLachlan
Biometrician

T: +64 6 355 6110
M: +64 212581882
F: +64 6 351 7050
E: andrew.mclachlan@plantandfood.co.nz
www.plantandfood.co.nz
The New Zealand Institute for Plant & Food Research Limited

Postal Address: Plant & Food Research
Private Bag 11600, Palmerston North 4442, New Zealand
Physical Address: Plant & Food Research
Food Industry Science Centre, Fitzherbert Science Centre, Batchelar Road, Palmerston North 4474, New Zealand

The contents of this e-mail are confidential and may be subject to legal privilege.
If you are not the intended recipient you must not use, disseminate, distribute or
reproduce all or any part of this e-mail or attachments. If you have received this
e-mail in error, please notify the sender and delete all material pertaining to this
e-mail. Any opinion or views expressed in this e-mail are those of the individual
sender and may not represent those of The New Zealand Institute for Plant and
Food Research Limited.

########################################################################

To unsubscribe from the GENSTAT list, click the following link:
https://www.jiscmail.ac.uk/cgi-bin/webadmin?SUBED1=GENSTAT&A=1

Post generated using Mail2Forum (http://www.mail2forum.com)

_________________
Andrew McLachlan
Plant & Food Research
Palmerston North, New Zealand
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
Post new topic

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum