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;
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
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
Hello, yes this is desired outcome, I probably had some issues with my session. Thanks for your help 😉
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.