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

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1363 views
  • 0 likes
  • 3 in conversation