Desktop productivity for business analysts and programmers

startdato-enddato

Reply
New Contributor
Posts: 4

startdato-enddato

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?

 

 

Grand Advisor
Posts: 17,355

Re: startdato-enddato

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

New Contributor
Posts: 4

Re: startdato-enddato

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

Grand Advisor
Posts: 17,355

Re: startdato-enddato

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? 

Grand Advisor
Posts: 17,355

Re: startdato-enddato

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. 

Esteemed Advisor
Posts: 6,661

Re: startdato-enddato

data test2;
set test1;
datoa = mdy(mod(aarm,100),1,int(aarm/100));
datoz = intnx('month',datoa,0,'end');
format datoa datoz yymmdd10.;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 4

Re: startdato-enddato

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?

Esteemed Advisor
Posts: 6,661

Re: startdato-enddato


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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 4

Re: startdato-enddato

KurtBremser...

 

thanks... Smiley Wink

Ask a Question
Discussion stats
  • 8 replies
  • 218 views
  • 0 likes
  • 3 in conversation