Hei,
I'm working with SAS, and I have this formatdate 200103;
I need to find the first and the last day in these dates, that's to say
først day would be 20010301
last day would be 20010331
I did this:
data test2;
set test1;
datoa=((aarm*100)+01);
datoz=input(put(((aarm*100)+1),z8.),yymmdd8.);
Run;
But I'm finding any most direct and short. Is this possible?
INTNX function. Look at the alignment parameter, with a 0 increment. The documentation has an example
Ok,
I did it now:
data test2;
set test1;
datoa=((aarm*100)+01);
datoz=put((intnx('month',(input(put(((aarm*100)+1),z8.),yymmdd8.)),1)-1),yymmddn8.);
Run;
Is that the only one way?
I'm finding any more short
That's ugly. Why all the put/input? Can't you store it as a SAS date?
Youre looking for how many days in a month?
Date = input( aarm, yymmn6.);
start_date=intnx('month', date, 0, 'b');
end_date=intnx('month', date, 0, 'e');
format date start_date end_date yymmdd8;
run;
If you really want, you can nest the functions to get rid of the first step, but I thought it helped for clarity.
data test2;
set test1;
datoa = mdy(mod(aarm,100),1,int(aarm/100));
datoz = intnx('month',datoa,0,'end');
format datoa datoz yymmdd10.;
run;
It was fine but I has recived like a result any like this:
2001-03-12
But I would like any with this formate:
20010312
Is this possible?
@EDB1 wrote:
It was fine but I has recived like a result any like this:
2001-03-12
But I would like any with this formate:
20010312
Is this possible?
If you meant my code, just change the format to yymmddn8.
Be aware that both my new variables contain SAS date values.
KurtBremser...
thanks... 😉
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.