BookmarkSubscribeRSS Feed
adil256
Quartz | Level 8

Hi to the community,

 

I try to get the value of different statistic test in a dataset (namely: CCC, PseudoFstat and Rsq) for each cluster number. To do so, i've writting this code. It seems to work  but i get a message error at the end.   Moreover, the code is very dirty, do you have any idea to simplify to get a similar final output which is dataset merge2 in my case.

 

Thank you for your help and patience.

 

Here is the error message:

92 GOPTIONS NOACCESSIBLE;

93 %LET _CLIENTTASKLABEL=;

94 %LET _CLIENTPROJECTPATH=;

95 %LET _CLIENTPROJECTNAME=;

96 %LET _SASPROGRAMFILE=;

97

98 ;*';*";*/;quit;run;

____

180

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.MERGE2 may be incomplete. When this step was stopped there were 0 observations and 4 variables.

WARNING: Data set WORK.MERGE2 was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

real time 0.07 seconds

cpu time 0.06 seconds

 

and the code.

 

%let min=3;
%Put &min;
%let max=5;
%put &max;
*options noquotelenmax;


%macro get_stat;
%do i = &min %to &max;
proc fastclus data=sashelp.gas out=result_&i outstat=stat_&i maxclusters=&i maxiter=1000 converge=0;
var CpRatio EqRatio NOx;

ods output CCC=myccc_&i(drop=label rename=(value=CCC));

ods output ApproxExpOverAllRSq = myR_&i (drop=label rename=(value=Rsq));

ods output PseudoFStat = myF_&i(drop=label rename=(value=PseudoFStat));

data myccc_&i;
set myccc_&i;
Cluster_number= put(&i,2.);

data myR_&i;
set myR_&i;
Cluster_number= put(&i,2.);

data myF_&i;
set myF_&i;
Cluster_number= put(&i,2.);

data append_db_1;
set myR_&min-myR_&max;
run;

data append_db_2;
set myccc_&min-myccc_&max;
run;

data append_db_3;
set myF_&min-myF_&max;
run;

proc sort data=append_db_1;
by Cluster_number;

proc sort data=append_db_2;
by Cluster_number;

proc sort data=append_db_3;
by Cluster_number;

Data merge1;
merge append_db_1 append_db_2;
by Cluster_number;

proc sort data=merge1;
by Cluster_number;

Data merge2;
merge merge1 append_db_3;
by Cluster_number;


%end;
%mend;
%get_stat;

 

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Your getting that message as you either have unbalanced quotes or the macor processor had an error and the macro string didn't stop.  Its very difficult to tell from what you post but that is not Base SAS, it is code injected by Enterprise Guide or something like that,its a horrible try to fix anything.

As a tip it is always a good idea to a) finish macro variables with a '.' , there are cases where not having it will result in errors so do it all the time.

b) finish blocks of code by the appropriate ending statement, run; for instance.  and C) Indent code so you can read it easily.

Now what is it your attempting to do with this code?  It looks like you are creating a load of datasets and merging them together and doing this repeatedly for a set of loops.  I can guarentee you that there is a better method than this.  Posting example test data/required output and we can see, but I suspect creating groups before doing the fastclus and then doing fastclus by <group>; would be far more efficient.

adil256
Quartz | Level 8

Thanks for the tips@RW9 and @Patrick,

 

Just noticed that I forget a run statement before %end; the error message is gone. 🙂

I'm using the dataset from sashelp library as input to show what I want to achieve.

My code works but it's very messy, cumbersome and not efficient. As you said, there areso much better ways to achieve the same result but I'm still blocked by my knowledge of the program. 🙂

 

How would you create the groups before using fastclus to cluster the observations?

 

Basically, I want the follwing table.

data want;
input cluster_number $ Rsq CCC PseudoFStat;
datalines;
 3 0.77830 4.562 406.72
 4 0.83543 7.598 484.97
 5 0.86969 9.308 540.43
;

 

 

 New version of the code :

%let min=3;
%Put &min;
%let max=5;
%put &max.;



%macro get_stat;

%do i = &min. %to &max.;

proc fastclus data=sashelp.gas out=result_&i. outstat=stat_&i. maxclusters=&i. maxiter=1000 converge=0;
var CpRatio EqRatio NOx;

ods output CCC=myccc_&i.(drop=label rename=(value=CCC));

ods output ApproxExpOverAllRSq = myR_&i. (drop=label rename=(value=Rsq));

ods output PseudoFStat = myF_&i.(drop=label rename=(value=PseudoFStat));

data myccc_&i.;
set myccc_&i.;
Cluster_number= put(&i.,2.);

data myR_&i.;
set myR_&i.;
Cluster_number= put(&i.,2.);

data myF_&i.;
set myF_&i.;
Cluster_number= put(&i.,2.);

data append_db_1;
set myR_&min.-myR_&max.;
run;

data append_db_2;
set myccc_&min.-myccc_&max.;
run;

data append_db_3;
set myF_&min.-myF_&max.;
run;

proc sort data=append_db_1;
by Cluster_number;

proc sort data=append_db_2;
by Cluster_number;

proc sort data=append_db_3;
by Cluster_number;

Data merge1;
merge append_db_1 append_db_2;
by Cluster_number;

proc sort data=merge1;
by Cluster_number;

Data want;
merge merge1 append_db_3;
by Cluster_number;
run;

%end;
%mend;
%get_stat;

 

Patrick
Opal | Level 21

@adil256

Just browsing through your code I can't see anything which obviously wouldn't work. 

The Error message you get can have many reasons and can be cause by something as simple as a missing semicolon.

 

To exclude that you "inherit" errors from previous runs in the same EG session I suggest you disconnect and reconnect to the server. This will create a new SAS session and gives you a clean start.

Should the Error remain then I suggest you add the following on top of your code:

ODS TRACE ON.

OPTIONS MPRINT MLOGIC SYMBOLGEN.

 

Then disconnect and reconnect once more from the SAS server, run the code and post the Log here in this forum (as an attachment or using the {i} button).

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 951 views
  • 0 likes
  • 3 in conversation