BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
japelin
Rhodochrosite | Level 12

I strongly recommend debugging to create a data step that works properly before create a macro code.

 

 

%macro testmacro;
data test1;
%let start_dt = '01jun2020'd;
%let add = (9 8 7 6 5 11 10);

do i=0 to 12;
varname = catt('month',put(i,z2. -l));   /* what does "-l" means? */
varvalue=intnx('month',"start_dt"d,+1*i,'b');/* change "start_dt"d to &start_dt */
format var_value date9.;                      /* var_value or varvalue? typo? */
call symputx(varname,put(varvalue,date9.) 'g');   /* "," needs before 'g' */

%let trialdate = %sysfunc(intnx(month,&start_dt,+1*i,b));/* why not using call symput(x) but using %let in data step  */
%let trialdate2 = %eval(&trialdate+%scan(&add,%sysfunc(weekday(&trialdate))));/* if you want to use %let change from do loop with i to %do loop with &i  */

output;
end;
run;
mend;
%testmacro;

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
  • 15 replies
  • 2521 views
  • 5 likes
  • 5 in conversation