Date: Fri, 19 Sep 2008 02:24:54 -0700
Reply-To: Ben <ben.dray@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ben <ben.dray@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: Identifying variables
Content-Type: text/plain; charset=ISO-8859-1
Hi both - thanks Dan for your speedy reply - I tried the cats function
but it just gave me RR1, RR2, RR3 and not the value of those variables
as I was after.
Jim, the array worked a treat thanks. I've left out the macro but I
still don't know why it didn't work. To elaborate on the rest of the
datastep I've got it below but yes, &var &var.M and &var.U are meant
to go to HR HRM and HRU respectively. The dataset I'm working on is
verticalised so the variable going into the select statement (QNAME)
has the HR et al. values in it...
%macro group(var, var2, var3,var4) ;
when ("&var") do i=1 to 3 ;
if qseq=i then qtext=g(&var4,i) ;
end ;
when ("&var.M") qtext=&var2 ; *qtext should equal the value found
in the hrtavg variable ;
when ("&var.U") qtext=&var3 ; *qtext should equal 83 ;
%mend group ;
data _2 ;
set _1 ;
select (qname) ;
array g[7,3] hr1-hr3 rr1-rr3 ss1-ss3 tt1-tt3 uu1-uu3 vv1-vv3 ww1-
ww3 ; *(thanks!)
/*...other when statements...*/
%group(HR,hrtavg,83,1) ;
%group(rr,rrm,8,2) ;
*...;
otherwise ;
end ;
run ;
On Sep 18, 5:13 pm, jim.1s...@YAHOO.COM (Jim Groeneveld) wrote:
> Hi Ben,
>
> "&var", "&var.M" and "&var.U" are the values "HR", "HRM", and "HRU" in the
> example, right? Which variable is called in the SELECT statement starting
> this whole issue and defining the variable to compare the values to?
> Anyway &Var2 and &Var3 are the variable name HrtAvg and the value 83
> respectively, is that as you intended it? So, qtext either is assigned the
> value of the variable HrtAvg or it is assigned the (numerical) value 83. OK?
>
> To indicate one of Rr1, Rr2 or Rr3, dependent of I is:
> ARRAY RR RR1 RR2 RR3;
> and in your code the assignment:
> if qseq=i then qtext=rr[i] ; * copy value from rr[i] to qtext;
>
> Before the statement
> %group(HR,hrtavg,83) ;
> you have the statement
> SELECT ~expression~, don't you?
> And after it you have an END; statement? No? That is where the error comes
> from: if not END then the SELECT is expected to continue with either of the
> 3 keywords.
>
> So rewriting your code:
>
> %macro group(var, var2, var3) ;
> when ("&var") do i=1 to 3 ;
> if qseq=i then qtext=rr[i] ;
> end ;
> when ("&var.M") qtext=&var2 ;
> when ("&var.U") qtext=&var3 ;
> %mend group ;
>
> ARRAY RR RR1 RR2 RR3;
> SELECT variable;
> %group(HR,hrtavg,83) ; ...
> END;
>
> Regards - Jim.
> --
> Jim Groeneveld, Netherlands
> Statistician, SAS consultant
> home.hccnet.nl/jim.groeneveld
>
> My computer and I present macro Count with SPSS-like syntax at PhUSE 2008.
>
>
>
> On Thu, 18 Sep 2008 08:32:36 -0700, Ben <ben.d...@GMAIL.COM> wrote:
> >Hi all,
>
> >I've got two questions here...I'm using a select case where some of
> >the values of the variable being checked are related, so (1) I was
> >hoping to replicate some of the when statement with a macro snippet as
> >below to save my fingers but I get an error "Expecting
> >"WHEN","OTHERWISE, or "END":
>
> >%macro group(var, var2, var3) ;
> > when ("&var") do i=1 to 3 ;
> > if qseq=i then qtext=rr||i ;
> > end ;
> > when ("&var.M") qtext=&var2 ;
> > when ("&var.U") qtext=&var3 ;
> >%mend group ;
> > %group(HR,hrtavg,83) ; ...
>
> >(2) I understand that "if qseq=i then qtext=rr||i" won't work but I
> >don't know how to make qtext equal to the rr1, rr2 and rr3 variables
> >on consecutive iterations.
>
> >Thanks in advance :)
>
> >Ben- Hide quoted text -
>
> - Show quoted text -
|