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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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