Help using Base SAS procedures

intnx

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 126
Accepted Solution

intnx

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. 


Accepted Solutions
Solution
‎03-23-2017 11:06 AM
Respected Advisor
Posts: 3,040

Re: intnx

format date yymmddn8.;
--
Paige Miller

View solution in original post


All Replies
Respected Advisor
Posts: 3,040

Re: intnx

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
Frequent Contributor
Posts: 126

Re: intnx

Posted in reply to PaigeMiller

How to do it please

Super User
Posts: 10,271

Re: intnx

Use the format statement.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎03-23-2017 11:06 AM
Respected Advisor
Posts: 3,040

Re: intnx

format date yymmddn8.;
--
Paige Miller
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 263 views
  • 1 like
  • 3 in conversation