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;

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1840 views
  • 0 likes
  • 2 in conversation