BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10
data a;                       
jan=intnx('month',01,0,'e');
feb=intnx('month',02,0,'e');
mar=intnx('month',03,0,'e');
apr=intnx('month',04,0,'e');
may=intnx('month',05,0,'e');
jun=intnx('month',06,0,'e');
jul=intnx('month',07,0,'e');
aug=intnx('month',08,0,'e');
sep=intnx('month',09,0,'e');
oct=intnx('month',10,0,'e');
nov=intnx('month',11,0,'e');
dec=intnx('month',12,0,'e');
run;    

How to count number of days each month wise

 

 

Regards,

anand

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
data a;
    do dt='01jan2019'd by 0 until (dt ge '31dec2019'd);
        dt=intnx('month', dt, 0, 'e');
        days=day(dt);
        output;
        dt=dt+1;
    end;
    format dt monname.;
run;

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20
data a;
    do dt='01jan2019'd by 0 until (dt ge '31dec2019'd);
        dt=intnx('month', dt, 0, 'e');
        days=day(dt);
        output;
        dt=dt+1;
    end;
    format dt monname.;
run;
BrahmanandaRao
Lapis Lazuli | Level 10

Hi draycut 

Code is running to long 

But  not correct output

PeterClemmensen
Tourmaline | Level 20

My code should not take too long. No data is being read, only 12 rows created.

 

For me to replicate the "correct" output, please post exactly what the correct output is.

 

 

Kurt_Bremser
Super User

@BrahmanandaRao wrote:

Hi draycut 

Code is running to long 


Can't be, @PeterClemmensen 's code takes just one hundredth of a second:

73         data a;
 74             do dt='01jan2019'd by 0 until (dt ge '31dec2019'd);
 75                 dt=intnx('month', dt, 0, 'e');
 76                 days=day(dt);
 77                 output;
 78                 dt=dt+1;
 79             end;
 80             format dt monname.;
 81         run;
 
 NOTE: The data set WORK.A has 12 observations and 2 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.01 seconds
       cpu time            0.00 seconds

and the result looks fine to me:

                                                     Beob.           dt    days

                                                        1       January     31 
                                                        2      February     28 
                                                        3         March     31 
                                                        4         April     30 
                                                        5           May     31 
                                                        6          June     30 
                                                        7          July     31 
                                                        8        August     31 
                                                        9     September     30 
                                                       10       October     31 
                                                       11      November     30 
                                                       12      December     31 

BrahmanandaRao
Lapis Lazuli | Level 10

Hi Draycut

 

Just i reopen my sas application and check your solution 

it's perfect output   

 

Thank You for your support 

 

Regards,

Anand

yabwon
Onyx | Level 15

Hi @BrahmanandaRao 

 

do you mean something like this:

 

data a;
  first_period = '1jan2018'd; 
  drop first_period;
  array Months jan feb mar apr may jun jul aug sep oct nov dec;

  do over Months; 
    Months = day(intnx('month',first_period, _i_-1, 'e'));
  end;
run; 

or a bit more general:

data first_period;
format first_period yymmdd10.;
first_period = '1jan2013'd; output;
first_period = '2feb2014'd; output;
first_period = '3mar2015'd; output;

first_period = '4apr2016'd; output;
first_period = '5may2017'd; output;
first_period = '6jun2018'd; output;

first_period = '7jul2019'd; output;
first_period = '8aug2020'd; output;
first_period = '9sep2021'd; output;

first_period = '10oct2022'd; output;
first_period = '11nov2023'd; output;
first_period = '12dec2024'd; output;
run;



data a;
  set first_period;
  array Months jan feb mar apr may jun jul aug sep oct nov dec;

  do over Months; 
    Months = day(intnx('month',first_period, _i_-month(first_period), 'e'));
  end;
run;  

All the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



BrahmanandaRao
Lapis Lazuli | Level 10

Hi  

 

 

Thank you for your initiative

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 934 views
  • 0 likes
  • 4 in conversation