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

Suppose I have two global macro variables called year and month that a user can change as need (or automatically set). I would like SAS to automatically create a dataset that has one variable called date and it will populate all the days on the month. So if year was set to 2020 and month was set to 5, then the dataset would be automatically created with all the days for May (31 of them) as YYMMDDS8. Is this possible?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Like this?

%let year = 2020;
%let month = 5;

data want;
    do dt = mdy(&month, 1, &year) by 1 while (month(dt)=&month);
       output;
    end;
    format dt yymmdds8.;
run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Like this?

%let year = 2020;
%let month = 5;

data want;
    do dt = mdy(&month, 1, &year) by 1 while (month(dt)=&month);
       output;
    end;
    format dt yymmdds8.;
run;

BCNAV
Quartz | Level 8

nice!  You original worked as well (I modified it to my needs...posted below for others).  Thanks for both!

 

%let year = 2020;
%let month = 2;

data egtask.DATE_LIST;
   do DATE = intnx('month', mdy(&month, 1, &year), 0, 'b') to 
      intnx('month', mdy(&month, 1, &year), 0, 'e');
         output;
   end;
   format DATE yymmdds8.;
run;

 

 

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
  • 3 replies
  • 1952 views
  • 0 likes
  • 2 in conversation