i have a data set containing the data of 365 days.
i want to extract the data of 1st of every month and last day of every month.
eg. if i have data of 3 months jan, feb,march then i want output data set to contain 1st jan, 31st jan, 1st feb, 28th feb, 1st march,31st march.
something like:
data monthBegEnd;
set myData;
if date = intnx("month", date, 0, "beginning") or
date = intnx("month", date, 0, "end") then output;
run;
a simple intnx with begin and end option
would be nice if you posted sample of what you have and what you desire as output
start_date value
1/1/2018 123
1/2/2018 124
1/3/2018 125
1/4/2018 126
1/5/2018 127
1/6/2018 128
1/30/2018 129
1/31/2018 130
2/1/2018 131
2/2/2018 132
2/3/2018 133
2/4/2018 134
2/27/2018 135
2/28/2018 136
3/1/2018 137
3/2/2018 138
3/3/2018 139
3/4/2018 140
3/5/2018 141
3/6/2018 142
3/7/2018 143
3/8/2018 144
3/29/2018 145
3/30/2018 146
3/31/2018 147
4/1/2018 148
4/2/2018 149
4/3/2018 150
Output Data B:
start_date value
1/1/2018 123
1/31/2018 130
2/1/2018 131
2/28/2018 136
3/1/2018 137
3/31/2018 147
4/1/2018 148
@PGStats code does that. 🙂
something like:
data monthBegEnd;
set myData;
if date = intnx("month", date, 0, "beginning") or
date = intnx("month", date, 0, "end") then output;
run;
It will extract all dates which are the first of the month or the last of the month. It will never select March 2, for example, even if March 1 is absent from your data.
Try it and see.
sas learning
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!
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.