BookmarkSubscribeRSS Feed
akosyan
Fluorite | Level 6

Hi,

 

Can you please help me with this ask ?

So I have

 

%let start_month = 1801

%let end_month = 1907

 

I want to create a datatable containing only one column which will have all the months from start to end. I am assuming I should append a new month values in a do loop.

 

Thanks,

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Hi and welcome to the SAS Community 🙂

 

Does 1801 represent january in 2018?

akosyan
Fluorite | Level 6

Thank you 🙂

 

yes 1801 is January 2018,

PaigeMiller
Diamond | Level 26

@akosyan wrote:

Hi,

 

Can you please help me with this ask ?

So I have

 

%let start_month = 1801

%let end_month = 1907

 

I want to create a datatable containing only one column which will have all the months from start to end. I am assuming I should append a new month values in a do loop.

 

Thanks,


Don't bother with macros.

 

data want;
    startmonth='01JAN18'd;
    endmonth='01JUL19'd;
    month=startmonth;
    do while(month le endmonth);
        output;
        month=intnx('month',month,1);
    end;
    keep month;
    format month yymm5.;
run;
--
Paige Miller
akosyan
Fluorite | Level 6

Thanks Paige,

 

It worked, except for the formatting I needed to put yymmn4.

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
  • 4 replies
  • 1178 views
  • 1 like
  • 3 in conversation