BookmarkSubscribeRSS Feed
msantosp
Fluorite | Level 6

Dear all,

 

I want to define recursively a data step inside of a macro but it it nos allow. I have the code below:

 

Anyone can help me to transform it in something that works? Thank you all

 


%do year=2017 %to 2019;

%do month=1 %to 12;

%do mod_id=8 %to 14;

data calibracion_&year.&month.&mod_id._2;
set test&year.&month.bmod_id&mod_id.;
format flag_event $2.;
flag_event = ind_incumplimiento;
output;
run;

title 'Logistic Regression: M008';

proc logistic data=calibracion_&year.&month.&mod_id._2 descending; /* To model 1s rather than 0s, we use the descending option */
model flag_event = raw_logit / clparm=wald;
ods output ParameterEstimates = calibration_&year.&month.&mod_id.;
run;

data _null_;
set calibration_&year.&month.&mod_id.;
if variable='Intercept' then call symputx('a_mod&year.&month.&mod_id',estimate);
if variable NE 'Intercept' then call symputx('b_mod&year.&month.&mod_id',estimate);
run;

%end; %end;%end;

%mend;

%parametros

 

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

@msantosp wrote:

Dear all,

 

I want to define recursively a data step inside of a macro but it it nos allow. I have the code below:

 

Anyone can help me to transform it in something that works? Thank you all


I would suggest you eliminate all of the macros and macro variables, append all of your data sets into 1 big one, and perform PROC LOGISTIC with a BY statement.

 

by year month mod_id;

 

You get the same results, with a lot less programming.

--
Paige Miller
Reeza
Super User
And append your output calibration data sets together to keep your estimates in a table, don't create a ton of macro variables.
Tom
Super User Tom
Super User

A few comments and questions.

It looks like you are NOT doing any recursion.  Just simple DO loops.  (If you every need to process parts of a year then you might want to loop over month offset number instead of YEAR and MONTH.  You can then calculate the date using INTNX() function that way you could loop from sep to june for example.)

 

Why did you attach the $2 format to the variable FLAG_EVENT?  Are you trying to truncate the values that are displayed to just the first two?  If you wanted to define it as new variable then just use LENGTH statement.  If you just want to use the first two characters of ind_incumplimiento you can use SUBSTR().  Note that there is no need to attach the $ format, SAS already knows how to display character variables so it does not need you to tell it to use some special FORMAT for them.

 

Why are you placing the ESTIMATE values into macro variables?  You do not seem to be using those macro variables for anything.

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 867 views
  • 4 likes
  • 4 in conversation