BookmarkSubscribeRSS Feed
Amalik
Calcite | Level 5

Hi,

I have following data;

permnodate
11/31/2008
21/31/2008
31/31/2008
12/29/2008
22/29/2008
3

2/29/2008

I am using following code,

data tmp1.firstandlastdates;
set tmp1.finaluse(keep=permno date);
by permno; /*finaluse is always sorted by permno date*/
retain firstdate;
date=intnx('month', date, 1)-1;
if first.permno then firstdate=date;
if last.permno then do;
lastdate=date;
output;
end;
run;

The results I am getting is in this form;

permnodatefirstdatelastdate
11/31/20081756217562
21/31/20081756217562
31/31/20081756217562
12/29/20081756217562
22/29/20081756217562
32/29/20081756217562

 

As you can see, the first and lastdates are not in date format but rather in some other form. What can be causing this?

1 REPLY 1
Reeza
Super User

They are dates you haven't applied a format yet. 

 

SAS stores dates as the number of days from January 1, 1960. 

 

Add a FORMAT statement to apply formats to your dates and they'll show up as desired.

 

format firstdate yymmddd10. lastdate date9.;

@Amalik wrote:

Hi,

I have following data;

permno date
1 1/31/2008
2 1/31/2008
3 1/31/2008
1 2/29/2008
2 2/29/2008
3

2/29/2008

I am using following code,

data tmp1.firstandlastdates;
set tmp1.finaluse(keep=permno date);
by permno; /*finaluse is always sorted by permno date*/
retain firstdate;
date=intnx('month', date, 1)-1;
if first.permno then firstdate=date;
if last.permno then do;
lastdate=date;
output;
end;
run;

The results I am getting is in this form;

permno date firstdate lastdate
1 1/31/2008 17562 17562
2 1/31/2008 17562 17562
3 1/31/2008 17562 17562
1 2/29/2008 17562 17562
2 2/29/2008 17562 17562
3 2/29/2008 17562 17562

 

As you can see, the first and lastdates are not in date format but rather in some other form. What can be causing this?


 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 585 views
  • 0 likes
  • 2 in conversation