Looped macro variables wont go through the macro - just first iteration stored

Accepted Solution Solved
Reply
Contributor
Posts: 44
Accepted Solution

Looped macro variables wont go through the macro - just first iteration stored

[ Edited ]

Hello everyone,

 

I am trying to figure out how to create two data sets by using code below. Spefically, first data set named test_2016-08 and the other named test_2016_09. At this stage the code fails to return second data set. Any suggestions? Thanks

 

%Macro m(country,cycle);

data _null_;

month_end_dt = put(intnx('month',mdy(substr("&cycle",1,length("&cycle")-2),1,substr("&cycle",length("&cycle")-1,2)),-1,'end'),date9.)||':23:59:59.000';

year = year(input(month_end_dt,date9.));

month = substr(compress(0||month(input(month_end_dt,date9.))),length(compress(0||month(input(month_end_dt,date9.))))-1,2);

year_month = cat(year,"_",month);

call symput('month_end_dt',put(input(month_end_dt,datetime22.3),datetime22.3));

call symput('ym',year_month);

run;

data test_&ym.;

a = "&month_end_dt.";

b = "&ym.";

run;

%mend m;

data _null_;

array x[1] $2 ('BG'/* 'CZ' 'DE' 'HU' 'PL' 'RU' 'SG' 'SK' 'TH'*/);

do j=1 to dim(x);

do i = 8 to 9;

country = x[j];

month = compress(i||'16');

call symput('country',country);

call symput('cycle',month);

call execute ('%m(&country,&cycle)');

end;

end;

run;


Accepted Solutions
Solution
‎02-13-2017 12:36 PM
Super Contributor
Posts: 474

Re: Macro Problem

Works here, although not sure if the output is what you expect.

 

a                      b

31JUL2016:23:59:59.000 2016_07

 

a                      b

31AUG2016:23:59:59.000 2016_08

 

 

Daniel Santos @ www.cgd.pt

View solution in original post


All Replies
Solution
‎02-13-2017 12:36 PM
Super Contributor
Posts: 474

Re: Macro Problem

Works here, although not sure if the output is what you expect.

 

a                      b

31JUL2016:23:59:59.000 2016_07

 

a                      b

31AUG2016:23:59:59.000 2016_08

 

 

Daniel Santos @ www.cgd.pt

Contributor
Posts: 44

Re: Macro Problem

Hello, yes this is desired outcome, I probably had some issues with my session. Thanks for your help ;-)

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 127 views
  • 1 like
  • 2 in conversation