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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 492 views
  • 1 like
  • 2 in conversation