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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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