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

  GenStat  ~  Procedure parameter question

AndrewMc
Posted: Thu Jun 28, 2018 2:41 am Reply with quote
Joined: 28 Jul 2008 Posts: 76
Thanks Steve!
This code has proved most useful. As you say, the contents of sty[]['stype'] differ with the LABELS setting.
‘dummy’ = LABELS not set.
‘text’ = LABELS set to a text structure (either with or without values)
‘*’ = LABELS set to an undefined structure.

For posterity, I have included some working code and test examples below.

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
SCALAR NDAT; VALU=1
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)"

"Detect LABELS being set, a la Steve Langton"
GETATTRIBUTE [ATTR=stype] LABELS[1...#NDAT]; SAVE=sty[1...#NDAT]
\ PRINT sty[][]
IF sty[1]['stype']$[1] .IN. !t('text','*')
\caption 'Detected!!!'; note
TEXT LABELS[1]; VALUE=gname
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 to an undefined structure'; stress
delete [r=y] txLab
AAAA SiteI,SiteII,SiteIII,SiteIV; LABEL=txLab
print txLab
AAAA SiteI,SiteII,SiteIII,SiteIV; LABEL=txLab
print txLab

caption 'Multiple DATA variates, LABELS set to an undefined text'; stress
delete [r=y] txLab
text 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
print txLab

Andrew McLachlan
Biometrician


From: GENSTAT-Request [mailto:GENSTAT@jiscmail.ac.uk] On Behalf Of Steve Langton
Sent: Wednesday, 27 June 2018 9:55 a.m.
To: GENSTAT@JISCMAIL.AC.UK
Subject: Re: Procedure parameter question



I usually use PARAMETER=dummy in procedures, but I’ve looked back and found one I wrote many years ago with PARAMETER=pointer. The way I got around the odd behaviour of SET/UNSET was to use the following lines, modified to use your parameter names:
SCALAR nvc;NVALUES(DATA)
GETAT [stype] LABELS[1...#nvc];sty[1...#nvc]
PRINT sty[][]

If LABELS is unset the sty[][] will be ‘dummy’, if it is set to a text structure they will be ‘text’.

I’m sure Roger or David will have a neater solution, but this seemed to work.

Steve

****************************************************************************
Steve Langton, Hallgarth, Leavening, Malton, N. Yorks. YO17 9SA
Phone: +44(0)1653 658346 Mobile: +44(0)7930478749
Email: stats@slangton.org.uk (stats@slangton.org.uk)
****************************************************************************


From: GENSTAT-Request <GENSTAT@jiscmail.ac.uk (GENSTAT@jiscmail.ac.uk)> On Behalf Of Andrew McLachlan
Sent: 26 June 2018 05:05
To: GENSTAT@JISCMAIL.AC.UK (GENSTAT@JISCMAIL.AC.UK)
Subject: Re: Procedure parameter question



Hi Murray

Yes, I had briefly thought of doing that, but as you say I then decided to try to use DATA as a simple list. I will give your approach some more thought.

Cheers,
Andrew Mc

Andrew McLachlan
Biometrician

From: GENSTAT-Request [mailto:GENSTAT@jiscmail.ac.uk (GENSTAT@jiscmail.ac.uk)] On Behalf Of Murray Hannah
Sent: Monday, 25 June 2018 11:47 a.m.
To: GENSTAT@JISCMAIL.AC.UK (GENSTAT@JISCMAIL.AC.UK)
Subject: Re: Procedure parameter question [SEC=UNCLASSIFIED]

Hi Andrew,

My work-around has been to use PARAMETER=dummy in the PROCEDURE directive, and to make the user supply the DATA explicitly as a pointer. This would mean specifying TYPE='pointer','text' instead of TYPE='variate','text' in the PARAMETER directive.

I expect you have thought of that but just want to make it work with DATA as a simple list. I will be interested to see responses to your question.

Regards
Murray.
********************************************************************************
Department of Economic Development, Jobs, Transport and Resources, Government of
Victoria, Victoria, Australia.

This email, and any attachments, may contain privileged and confidential
information. If you are not the intended recipient, you may not distribute or
reproduce this e-mail or the attachments. If you have received this message in
error, please notify us by return email.
********************************************************************************



To unsubscribe from the GENSTAT list, click the following link:
https://www.jiscmail.ac.uk/cgi-bin/webadmin?SUBED1=GENSTAT&A=1
Quote:
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


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