Make code more efficient

Reply
Occasional Contributor
Posts: 8

Make code more efficient

[ Edited ]

Hi,

 

Could somenoe help me to make this code more efficient by appending proc iml operations together? 

 

%macro iverciai(imtis, rezultatai);
%let eil_imtis_nuo=1; 
/* 	SASFILE &imtis load; */

	proc sql noprint;
		select max(imtis)
		into :imciu_sk
		from &imtis;                                                                                                                                                                  
	quit;
	
	%do eil_imtis=&eil_imtis_nuo %to &imciu_sk;
		data x(keep=Xx);
		set &imtis;
		where imtis=&eil_imtis;
	run;

	%wacf(infile=x,
			varts=xx, 
			varws=,
			outfile=acf2,
			corr=SPEARMAN,
			kk=15, 
			alpha=0.05);
	
	data acf;
		set acf2;
		if _N_ = 1 then delete;
	run;

	proc iml;                                                                                                                                                          
         %if &eil_imtis>1 %then %str(use &rezultatai._kvadr;  read all into Kvadratine_FK;  close &rezultatai._kvadr; );
         use teorinesACF;  read all var{COL1} into f;  close teorinesACF;
         use ACF;  read all var{ACF} into f_FK;  close ACF;
         f_FK=(f_FK<1000)#f_FK;
            %if &eil_imtis>1 %then %str(Kvadratine_FK=Kvadratine_FK//((f-f_FK)##2)[:]; );
         %else %str(Kvadratine_FK=((f-f_FK)##2)[:]; );
                                                                                                                                                                    
         varnames='Kvadratine';
         create &rezultatai._kvadr from Kvadratine_FK [colname=varnames];
         append from Kvadratine_FK;
	quit;
	
	proc iml;                                                                                                                                                          
         %if &eil_imtis>1 %then %str(use &rezultatai._abs;  read all into Absoliutine_FK;  close &rezultatai._abs; );
         use teorinesACF;  read all var{COL1} into f;  close teorinesACF;
         use ACF;  read all var{ACF} into f_FK;  close ACF;
         f_FK=(f_FK<1000)#f_FK;
			%if &eil_imtis>1 %then %str(Absoliutine_FK=Absoliutine_FK//(abs(f-f_FK))[:]; );
         %else %str(Absoliutine_FK=(abs(f-f_FK))[:]; );
         varnames='Absoliutine';
         create &rezultatai._abs from Absoliutine_FK [colname=varnames];
         append from Absoliutine_FK;
	quit;
	
	proc iml;                                                                                                                                                          
         %if &eil_imtis>1 %then %str(use &rezultatai._sant;  read all into Santykine_FK;  close &rezultatai._sant; );
         use teorinesACF;  read all var{COL1} into f;  close teorinesACF;
         use ACF;  read all var{ACF} into f_FK;  close ACF;
         f_FK=(f_FK<1000)#f_FK;
			%if &eil_imtis>1 %then %str(Santykine_FK=Santykine_FK//((abs(f-f_FK))/abs(f))[:]; );
         %else %str(Santykine_FK=((abs(f-f_FK))/abs(f))[:]; );
         varnames='Santykine';
         create &rezultatai._sant from Santykine_FK [colname=varnames];
         append from Santykine_FK;
	quit;

	%end;
			 
        proc means data=&rezultatai._kvadr;                                                                                                                              
      		var Kvadratine;                                                                                                                                                 
      		output out=&rezultatai._kvadr_vid;                                                                               
   		run;
   		
   		proc means data=&rezultatai._abs;                                                                                                                              
      		var Absoliutine;                                                                                                                                                 
      		output out=&rezultatai._abs_vid;                                                                               
   		run;
   		
   		proc means data=&rezultatai._sant;                                                                                                                              
      		var Santykine;                                                                                                                                                 
      		output out=&rezultatai._sant_vid;                                                                               
   		run;
	
/* 	SASFILE &imtis close; */
%mend iverciai;
Super User
Super User
Posts: 7,942

Re: Make code more efficient

Posted in reply to ascasfaegADGSgs

Sorry, that code is very hard to read, is incomplete, and there is no test data to run it on.  I am only here to answer specific questions, not to code solutions for people.

 

What I would say is the following tips:

There is no need to use macro - as far as I checked - here, look up the use of by groups and arranging your data in such a way that by group processing is possible - this is the most efficient way of dealing with data and avoids all these macro loops, creating lots of datasets etc.

 

Simplify your dataset, there are lots of variable names and maro variables with long names which are meaningless to me.

 

What is %wacf?  Not defined anywhere.

 

The easiest way to get answers - post test data in the form of a datastep, and what the output should look like, then describe the logic to get from one to the other.

Super User
Posts: 10,020

Re: Make code more efficient

Posted in reply to ascasfaegADGSgs

I think your SAS syntax is not right . What is it for ?

%else %str(Santykine_FK=((abs(f-f_FK))/abs(f))[:]; );

Plz post it at SAS/IML Software and Matrix Computations

Since it is about IML .

 

Ask a Question
Discussion stats
  • 2 replies
  • 319 views
  • 0 likes
  • 3 in conversation