Date: Tue, 12 May 1998 09:50:56 -0400
Reply-To: "abdu.elnagheeb(a)nationsbank.com"
<abdu.elnagheeb@NATIONSBANK.COM>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: "abdu.elnagheeb(a)nationsbank.com"
<abdu.elnagheeb@NATIONSBANK.COM>
Subject: Macro Error
Hello everyone,
I will appreciate your help on finding the error in this macro.
When I ran the macro, I got the following error message:
************Part of Log where error appears************;
NOTE: Line generated by the invoked macro "RANKIT".
408
if LAST.&Xvar then output temp2;
-----
455
MPRINT(RANKIT): IF LAST.X THEN OUTPUT TEMP2;
MPRINT(RANKIT): IF EOF THEN OUTPUT TEMP3;
MPRINT(RANKIT): END;
MPRINT(RANKIT): RUN ;
ERROR 455-185: Dataset was not specified on the DATA statement.
**************Log part ends**********************
I'm confused because it seems that the line: if LAST.&Xvar then
output temp2 ; does NOT resolve. But the MPRINT shows it does. I
don't know what does SAS mean by that error 455.
Thanks for your help.
abdu
********************************************************;
options mprint symbolgen ;
data test ;
do i=1 to 20 ;
x= rannor(987) ;
y= ranuni(987) ;
if i <= 10 then wgt = 2.345 ;
else wgt = 3.123 ;
output ;
end;
run;
%let wgt = wgt ;
**********************Macro******************************;
%macro Rankit(dset,Xvar,dvar,nogrps,outset);
proc sort data=&dset out=&outset ;
by &Xvar;
run ;
* these 2 steps create a variable that is the sum of the weights *;
* and creates a variable that is the rank of the observation *;
data tempo (keep=rank &Xvar &dvar common cwgt &wgt)
temp3 (keep=sumwgt &Xvar &dvar common );
set &outset end=eof;
by &Xvar;
common = 1;
if &Xvar ne . then do;
if first.&Xvar then do;
cwgt = 0;
end;
sumwg + wgt ;
cwgt + wgt ;
rank + wgt ;
if LAST.&Xvar then output temp2;
if eof then output temp3;
end;
run ;
*this data step appends the total sum of the weights to each record *;
*of the file containing the unique x values, the sum of the weights*;
*for each unique x value, and the rank (cumulative sum of the *;
*weights) for each unique x value *;
data tempo;
merge temp3 tempo;
by common;
drop common;
run ;
* this step appends the sum of the weights and the ranks to the
records of the sorted dataset and creates the rank variable *;
* ties=mean option *;
data &outset ;
merge tempo &outset ;
by &Xvar;
retain oldvar rtestvar ;
if &Xvar ne . then do;
if &Xvar > oldvar then do;
rtestvar = 2*rank*&nogrps+(1-cwgt)*&nogrps)/(2*(sumwgt+1));
rtestvar = floor(rtestvar);
end;
oldvar = &Xvar;
end;
data &outset ;
set &outset (rename=(&Xvar=TestVar)) ;
run;
%mend Rankit;
****************************************************;
%RANKIT(WORK.test,x,y,20,WORK.TEMP2);