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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
DanielSantos
Barite | Level 11

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

2 REPLIES 2
DanielSantos
Barite | Level 11

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

Uknown_user
Quartz | Level 8

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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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