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 😉
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: