BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasphd
Lapis Lazuli | Level 10

I use intnx function but it give date format diffirent from I want 

 

data firstandlastdates;
     set crsp.msf(keep=permno date);
     by permno; /*MSF 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;
  
  data permnosrankdates(rename=(date=rankdate));
      set firstandlastdates;
      date=firstdate;
      do while(date<=lastdate);
         output;
	 date=intnx('month', date+1, 1)-1;
      end;
  run;
 data permnosrankdates;
     set permnosrankdates;
     date=rankdate;
     i=1;
     do while(i<=24);
         output;
         date=intnx('month', date, 0)-1;
	 i=i+1;
     end;
  run;

the result that I want

Obs      PERMNO    rankdate         date     i

                  1       10000    19851231    19851231     1
                  2       10000    19851231    19851130     2
                  3       10000    19851231    19851030     3
                  4       10000    19851231    19850930    4
                  5       10000    19851231    19850831     5
                 ......

 the result i GOT

                 Obs      PERMNO    rankdate         date     i

                  1       10000    19851231    1986           1
                  2       10000    19851231    8476           2
                  3       10000    19851231    2356           3
                  4       10000    19851231                   4
                  5       10000    19851231                   5
                 

So I want to good date format YYMMDDN8. 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
format date yymmddn8.;
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

You need to assign the format you want to variable date when you create it in the data set. This has nothing to do with INTNX

--
Paige Miller
sasphd
Lapis Lazuli | Level 10

How to do it please

PaigeMiller
Diamond | Level 26
format date yymmddn8.;
--
Paige Miller

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1141 views
  • 1 like
  • 3 in conversation