BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RobF
Quartz | Level 8

I'm working on a SAS program that runs a coordinate descent algorithm which repetitively processes & updates dataset variables inside a macro loop:

%macro test(dataset=, numvars=, numiter=, lambda=, alpha=);

%do i=1 %to &numiter;

     %do j=1 %to &numvars;

           data &dataset (keep=y x1-x&numvars);

           set &dataset end=end_data;

                array x[&numvars] x1-x&numvars;

                                             < ... Code for variable manipulations & calculations ...>

           run;

     %end;

%end;

%mend;

%test(dataset=&dataset, numvars=10, numiter=100, lambda=.1, alpha=1)

I wrote this code out of convenience, realizing that putting a data step inside the macro loop isn't terribly efficient since opening and closing the same dataset eats up CPU resources.

Is there a better way to code this algorithm that will save significant time when running?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

In part, that depends on the calculations.  It is extremely likely you could recode along these lines:

data &dataset;

set &dataset end=end_data;

array x ...;

do _i_=1 to &numiter;

do _j_=1 to &numvars;

** calculate, possibly exactly as before;

end;

end;

run;

View solution in original post

1 REPLY 1
Astounding
PROC Star

In part, that depends on the calculations.  It is extremely likely you could recode along these lines:

data &dataset;

set &dataset end=end_data;

array x ...;

do _i_=1 to &numiter;

do _j_=1 to &numvars;

** calculate, possibly exactly as before;

end;

end;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 1 reply
  • 725 views
  • 1 like
  • 2 in conversation