BookmarkSubscribeRSS Feed
EDB1
Calcite | Level 5

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?

 

 

8 REPLIES 8
Reeza
Super User

INTNX function. Look at the alignment parameter, with a 0 increment. The documentation has an example 

EDB1
Calcite | Level 5

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

Reeza
Super User

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? 

Reeza
Super User

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. 

Kurt_Bremser
Super User
data test2;
set test1;
datoa = mdy(mod(aarm,100),1,int(aarm/100));
datoz = intnx('month',datoa,0,'end');
format datoa datoz yymmdd10.;
run;
EDB1
Calcite | Level 5

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?

Kurt_Bremser
Super User

@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.

EDB1
Calcite | Level 5

KurtBremser...

 

thanks... 😉

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1987 views
  • 0 likes
  • 3 in conversation