BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

I found a bug about SAS, a data step in a macro runs the dosubl function, the dosubl function calls the FCMP function, and the FCMP function runs the macro, which will cause the crash problem!

/*this is macro*/
%MACRO SORTS;
%LET INPUT_TABLE=%SYSFUNC(DEQUOTE(&INPUT_TABLE));
	%LET VARIABLE=%SYSFUNC(DEQUOTE(&VARIABLE));
PROC SORT DATA=&INPUT_TABLE;
	BY &VARIABLE;
 RUN;
%MEND SORTS;

/*this is fcmp function*/
PROC FCMP OUTLIB=WORK.FUNCS.MATH;
	FUNCTION SORTS_MACRO(INPUT_TABLE $,VARIABLE $);
		RC=RUN_MACRO('SORTS',INPUT_TABLE,VARIABLE);
		RETURN(RC);
	ENDSUB;

/*this is data step and new macro*/
OPTION CMPLIB=(WORK.FUNCS);
DATA _NULL_;
RC=DOSUBL("
	PROC CLUSTER DATA =&DATANAME METHOD=MCQUITTY SIMPLE CCC STD RSQUARE PSEUDO OUTTREE=&OUTNAME1;
		VAR _2021 _2020 _2019 _2018;
			ID CITY;
	RUN;
PROC TREE DATA=&OUTNAME1 OUT=&OUTNAME2 NCLUSTERS=3;
	ID CITY;
RUN; 
OPTIONS CMPLIB=WORK.FUNCS;
DATA  _NULL_;
	RC=SORTS_MACRO('&DATANAME','CITY');
		RC=SORTS_MACRO('&OUTNAME2','CITY');
RUN;");

RUN;

 

1 ACCEPTED SOLUTION

Accepted Solutions
AhmedAl_Attar
Rhodochrosite | Level 12

@_Sas_Beginner_ 

I personally would try to avoid all this convoluted mixture of techniques!

Try to simplify and isolate operations into their own individual units/functions/macros if you can, here is why

  1. It will provide better traceable/understandable code. Think of who will have to take over your code in the future
  2. When code modules are separated/decoupled, they can work in parallel as and when needed
  3. SAS provided various ways to run custom code, but that doesn't mean one should mix them just for the sake of it. Always try to think "Horses for Courses". i.e. choose the right technique for the right purpose.

Take a step back, and re-analyze what's your ultimate goal from your custom code, and reevaluate what needs to be coupled vs. decoupled.

 

This is all I can advice you with

 

View solution in original post

6 REPLIES 6
_Sas_Beginner_
Quartz | Level 8
/*This is how the last step should be*/
%MACRO CLUSTERS (DATANAME,OUTNAME1,OUTNAME2,OUTNAME3,FILE);
OPTION CMPLIB=(WORK.FUNCS);
DATA _NULL_;
RC=DOSUBL("
	PROC CLUSTER DATA =&DATANAME METHOD=MCQUITTY SIMPLE CCC STD RSQUARE PSEUDO OUTTREE=&OUTNAME1;
		VAR _2021 _2020 _2019 _2018;
			ID CITY;
	RUN;
PROC TREE DATA=&OUTNAME1 OUT=&OUTNAME2 NCLUSTERS=3;
	ID CITY;
RUN; 
OPTIONS CMPLIB=WORK.FUNCS;
DATA  _NULL_;
	RC=SORTS_MACRO('&DATANAME','CITY');
		RC=SORTS_MACRO('&OUTNAME2','CITY');
RUN;");

RUN;

%CLUSTERS(SASMAP.CLUSTERS,CLUST,TERR,SGPLOT,CLUSTERS.RTF);
Oligolas
Barite | Level 11

Hi,

right now and with the information you provided, I can not say if and why it would make sense to write code in this way and not like this:

%MACRO CLUSTERS (DATANAME,OUTNAME1,OUTNAME2,OUTNAME3,FILE);
      PROC CLUSTER DATA =&DATANAME. METHOD=MCQUITTY SIMPLE CCC STD RSQUARE PSEUDO OUTTREE=&OUTNAME1.;
      	VAR _2021 _2020 _2019 _2018;
      	ID CITY;
      RUN;
      PROC TREE DATA=&OUTNAME1. OUT=&OUTNAME2. NCLUSTERS=3;
      	ID CITY;
      RUN; 
      PROC SORT DATA=&DATANAME.;
      	BY CITY;
      RUN;
%MEND CLUSTERS;

%CLUSTERS(SASMAP.CLUSTERS,CLUST,TERR,SGPLOT,CLUSTERS.RTF;

 

________________________

- Cheers -

_Sas_Beginner_
Quartz | Level 8
thanks for You..reply,I will.try it
yabwon
Meteorite | Level 14

Why you want it to be so over-ove-over-complicated?? (yes, I repeated it 3 times)

 

You can achieve the same effect by simple:

/* sorting macro*/
%MACRO SORTS(INPUT_TABLE,VARIABLE);
PROC SORT DATA=&INPUT_TABLE;
	BY &VARIABLE;
 RUN;
%MEND SORTS;


/* This is how the last step should be... */
%MACRO CLUSTERS (DATANAME,OUTNAME1,OUTNAME2,OUTNAME3,FILE);
PROC CLUSTER DATA =&DATANAME METHOD=MCQUITTY SIMPLE CCC STD RSQUARE PSEUDO OUTTREE=&OUTNAME1;
  VAR _2021 _2020 _2019 _2018;
  ID CITY;
	RUN;

PROC TREE DATA=&OUTNAME1 OUT=&OUTNAME2 NCLUSTERS=3;
	ID CITY;
RUN; 

%SORTS(&DATANAME,CITY)
%SORTS(&OUTNAME2,CITY)
%mend;

%CLUSTERS(SASMAP.CLUSTERS,CLUST,TERR,SGPLOT,CLUSTERS.RTF);

No FCMP, run_macro(), etc.  (in this situation absolutely unnecessary).

Bart

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



_Sas_Beginner_
Quartz | Level 8
Thank You for your answer,I will try
AhmedAl_Attar
Rhodochrosite | Level 12

@_Sas_Beginner_ 

I personally would try to avoid all this convoluted mixture of techniques!

Try to simplify and isolate operations into their own individual units/functions/macros if you can, here is why

  1. It will provide better traceable/understandable code. Think of who will have to take over your code in the future
  2. When code modules are separated/decoupled, they can work in parallel as and when needed
  3. SAS provided various ways to run custom code, but that doesn't mean one should mix them just for the sake of it. Always try to think "Horses for Courses". i.e. choose the right technique for the right purpose.

Take a step back, and re-analyze what's your ultimate goal from your custom code, and reevaluate what needs to be coupled vs. decoupled.

 

This is all I can advice you with

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 238 views
  • 3 likes
  • 4 in conversation