| Date: | Fri, 15 Dec 2006 08:52:59 +0800 |
| Reply-To: | Excimer_Gong <Excimer_Gong@SMICS.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Excimer_Gong <Excimer_Gong@SMICS.COM> |
| Subject: | Re: Macro Error |
|
| In-Reply-To: | A<7367b4e20612140617w5d0131a3q18838cbb7da87bad@mail.gmail.com> |
| Content-Type: | text/plain; charset="gb2312" |
Data _null_, David and Howard;
Thanks for your help. What I am doing is:
We have an oracle database collecting real time data, the oracle database has a table Table_A with 3 related columns: ID, Data, Time
1. Read data from the Table_A into SAS for each ID with just the most recent 1000 records
2. Classifying the data into grouping 1 to 4 based on the count of distinct values, autocorrelation, and normality check after outlier excluding. (as detail coding below)
3. Update the oracle database Table_B the grouping result (table_B has 2 related columns: ID, Grouping)
4. Repeat step 1 to step 3 until all IDs are done.
The purpose is: other windows programs will analysis Table_A data based on the grouping result
My mentioned macro is part of the job (for step 2, classifying the data), Q1, Q2 and Q3 are used to exclude the outliers.
Can you help suggest whether there is better solution to this task.
%macro SPCGrouping(varname=, dataset=);
proc sql noprint;
select count(distinct &varname) into :numRows from &dataset;
quit;
%put Distinct Rows=**&numRows**;
%let GROUPING = 2;
%if &numRows < 2 %then %let GROUPING = 1;
%if &numRows > 10 %then %let GROUPING = 3;
%if &numRows > 10 %then %do;
proc arima data= &dataset;
identify var=&varname nlag=10 OUTCOV=WORK.arimaout noprint;
run; quit;
proc sql noprint;
select count(CORR) into :CORR from arimaout where LAG>0 and abs(CORR)>0.2 and abs(CORR)>2*STDERR ;
drop table arimaout;
quit;
%put CORR=**&CORR**;
%if &CORR < 1 %then %do;
PROC UNIVARIATE NOPRINT DATA = &dataset;
VAR &varname;
output out=QQ Q1=Q1 Q3=Q3 MEDIAN=Q2 PROBN=p_value;
run;
Proc sql noprint;
Select Q1,Q2,Q3 into :Q1,:Q2,:Q3, :Q from QQ;
drop table QQ;
quit;
%if (&Q1 NE &Q3) %then %do;
Proc sql noprint;
Create table PARA_VALUE as Select &varname, 5.9303*&Q1-4.9303*&Q2,5.9303*&Q3-4.9303*&Q2 from &dataset where &varname between 5.9303*&Q1-4.9303*&Q2 and 5.9303*&Q3-4.9303*&Q2;
quit;
PROC UNIVARIATE NOPRINT DATA = PARA_VALUE;
VAR &varname;
output out=QQ2 Q1=Q1 Q3=Q3 MEDIAN=Q2 PROBN=p_value;
run;
Proc sql noprint;
select P_Value into:P_Value from QQ2;
quit;
%put P_Value=**&P_Value**;
%if &P_Value > 0.05 %then %let GROUPING = 4;
Proc sql noprint;
drop table QQ2;
drop table PARA_VALUE;
quit;
%end;
%end;
%end;
%put GROUPING=**&GROUPING**;
%mend;
%let GROUPING = -1;
%spcgrouping (varname=chart_inx, dataset=b);
%put GROUPING=**&GROUPING**;
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of data _null_;
Sent: 2006Äê12ÔÂ14ÈÕ 22:18 GB
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Macro Error
In this situation SYSEVALF will solve the problem. This was discussed just yesterday here on SAS-L.
Will you tell us more about what you are trying to accomplish.
Putting data into macro variables as you have done may not be the best solution. But without more info it is hard to tell.
data work.qq;
q1=-1.1;
q2=3;
q3=1;
run;
%macro A;
Proc sql noprint; Select Q1,Q2,Q3 into :Q1,:Q2,:Q3 from QQ; quit;
%if %sysevalf(&Q1 NE &Q3,boolean) %then %do;
%put NOTE: Q1=&q1, Q2=&q2, Q3=&q3;
**other coding**;
%end;
%mend;
options mlogic;
%a;
On 12/14/06, Excimer_Gong <Excimer_Gong@smics.com> wrote:
> I have a macro as:
>
> %macro A;
>
> Proc sql noprint;
> Select Q1,Q2,Q3 into :Q1,:Q2,:Q3 from QQ;
> quit;
> %if (&Q1 NE &Q3) %then %do;
> **other coding**;
> %end;
>
> %mend;
>
> The macro works well when both Q1 and Q3 > 0, but error occurs when Q1
> <0 or Q3 < 0. Can any one help me!
>
> ERROR: A character operand was found in the %EVAL function or %IF
> condition where a numeric
> operand is required. The condition was: (&Q1 NE &Q3)
> ERROR: The macro A will stop executing.
>
|