<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to make the firm(PERMNO) not classified again within one month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-the-firm-PERMNO-not-classified-again-within-one/m-p/926981#M364827</link>
    <description>&lt;P&gt;Got it now! thx!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DM'LOG; CLEAR; OUT; CLEAR; ODSRESULTS; CLEAR;';
%LET FOLDER=%STR(C:\USERS\ALAIN\ONEDRIVE\桌面\HIGH);
LIBNAME HIGH "&amp;amp;FOLDER";

DATA HH;
 SET HIGH.HH;
 IF CFACPR=0 THEN DELETE;
RUN;

DATA HH;
	SET	HH;
	IF _N_ &amp;lt;=1000;
RUN;

PROC SORT 
  DATA=HH (KEEP  =SHRCD EXCHCD PERMNO DATE PRC CFACPR SHROUT CFACSHR
                      WHERE =( SHRCD IN (10,11) AND EXCHCD IN (1,2,3,31,32,33) )
                      ) 

OUT=HL(DROP=SHRCD EXCHCD );
  BY PERMNO DATE;
RUN;

DATA HL; 
    SET HL; 
    BY PERMNO DATE; 
    RETAIN H L 0; 
    P=ABS(DIVIDE (PRC, CFACPR));
    IF FIRST.PERMNO THEN H = P; 
    IF FIRST.PERMNO THEN L = P;
    H = MAX(H, P); 
    L = MIN(L, P);
 DROP  PRC CFACPR;
   RUN; /* PERMNO DATE  SHROUT CFACSHR H L P */

data MK (drop=_:);
  set HL;
  BY PERMNO date; 

  retain _first_date_qualified . 
         _H   .                 
         _H_date .              
         _L   .                 
         _L_date .              
          PORTFOLIO 
;             
LENGTH  PORTFOLIO $11;

  if first.permno then do;
    call missing(of _:);
    _first_date_qualified=intnx('year',date,1,'same')+1;
  end;

  if _H=. then _H=P;
  if _L=. then _L=P;

  if P ^=. then do;
    if P &amp;gt; _H and date &amp;gt;= INTNX('MONTH', _H_DATE, 1, 'SAME')) then do;
      _H=P;
      _H_date=date;
      portfolio='Max';
    end;

    else if P &amp;lt; _L and date &amp;gt;= INTNX('MONTH', _L_DATE, 1, 'SAME')) then do;
      _L=P;
      _L_date=date;
      portfolio='Min';
    end;

    else portfolio='Comparison';
  end;

  if date &amp;gt;= _first_date_qualified then do;
      H = _H;
      H_date = _H_date;
      L = _L;
      L_date = _L_date;
  end;

  if date &amp;lt; _first_date_qualified then do;
    portfolio = 'Unqualified';
  end;

  format H_date L_date yymmdd10. ;

run;

DATA MK;
  SET MK(OBS=500);
  PUT (_ALL_) (+0);
RUN;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 04 May 2024 08:56:47 GMT</pubDate>
    <dc:creator>Irenelee</dc:creator>
    <dc:date>2024-05-04T08:56:47Z</dc:date>
    <item>
      <title>How to make the firm(PERMNO) not classified again within one month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-the-firm-PERMNO-not-classified-again-within-one/m-p/926979#M364825</link>
      <description>&lt;P&gt;How to make the firm(PERMNO) not classified into Min&lt;A title="Data" href="https://drive.google.com/file/d/1grx_6p-yVMVzrzvVjdtfwyFUjRpq10W6/view?usp=sharing" target="_self"&gt;https://drive.google.com/file/d/1grx_6p-yVMVzrzvVjdtfwyFUjRpq10W6/view?usp=sharing&lt;/A&gt;&amp;nbsp; again within one month? Thx!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MK (drop=_:);
  set HL;
  by permno;

  retain _first_date_qualified . 
         _H   .                 
         _H_date .              
         _L   .                 
         _L_date .              
          PORTFOLIO .
;             
LENGTH  PORTFOLIO $11;

  if first.permno then do;
    call missing(of _:);

_first_date_qualified=intnx('year',date,1,'same')+1;

 if date &amp;lt; _first_date_qualified then do;
    portfolio = 'Unqualified';

	END;
 
  if _H=. then _H=P;
  if _L=. then _L=P;

  if P ^=. then do;
    if P &amp;gt; _H AND NOT (PORTFOLIO='MAX' AND DATE &amp;lt; INTNX('MONTH', _H_DATE, 1, 'SAME'))  then do;
      _H=P;
      _H_date=date;
      portfolio='Max';
    end;

    else if P &amp;lt; _L AND NOT (PORTFOLIO='MIN' AND DATE &amp;lt; INTNX('MONTH', _L_DATE, 1, 'SAME')) then do;
      _L=P;
      _L_date=date;
      portfolio='Min';
    end;

    else portfolio='Comparison';
  end;

  if date &amp;gt;= _first_date_qualified then do;
    H=_H;
    H_date=_H_date;
    L=_L;
    L_date=_L_date;
  end;

  format H_date L_date yymmdd10. ;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;10000 1987-03-02 3893 1 4.4375 0.375 0.375 Min 1986-01-27 1987-03-02&lt;BR /&gt;10000 1987-03-03 3893 1 4.4375 0.375 0.375 Comparison 1986-01-27 1987-03-02&lt;BR /&gt;10000 1987-03-04 3893 1 4.4375 0.375 0.375 Comparison 1986-01-27 1987-03-02&lt;BR /&gt;10000 1987-03-05 3893 1 4.4375 0.359375 0.359375 Min 1986-01-27 1987-03-05&lt;BR /&gt;10000 1987-03-06 3893 1 4.4375 0.359375 0.359375 Comparison 1986-01-27 1987-03-05&lt;BR /&gt;10000 1987-03-09 3893 1 4.4375 0.359375 0.359375 Comparison 1986-01-27 1987-03-05&lt;BR /&gt;10000 1987-03-10 3893 1 4.4375 0.359375 0.390625 Comparison 1986-01-27 1987-03-05&lt;BR /&gt;10000 1987-03-11 3893 1 4.4375 0.359375 0.390625 Comparison 1986-01-27 1987-03-05&lt;BR /&gt;10000 1987-03-12 3893 1 4.4375 0.359375 0.390625 Comparison 1986-01-27 1987-03-05&lt;BR /&gt;10000 1987-03-13 3893 1 4.4375 0.359375 0.40625 Comparison 1986-01-27 1987-03-05&lt;BR /&gt;10000 1987-03-16 3893 1 4.4375 0.359375 0.40625 Comparison 1986-01-27 1987-03-05&lt;BR /&gt;10000 1987-03-17 3893 1 4.4375 0.359375 0.390625 Comparison 1986-01-27 1987-03-05&lt;BR /&gt;10000 1987-03-18 3893 1 4.4375 0.359375 0.390625 Comparison 1986-01-27 1987-03-05&lt;BR /&gt;10000 1987-03-19 3893 1 4.4375 0.34375 0.34375 Min 1986-01-27 1987-03-19&lt;BR /&gt;10000 1987-03-20 3893 1 4.4375 0.34375 0.34375 Comparison 1986-01-27 1987-03-19&lt;BR /&gt;10000 1987-03-23 3893 1 4.4375 0.34375 0.34375 Comparison 1986-01-27 1987-03-19&lt;BR /&gt;10000 1987-03-24 3893 1 4.4375 0.328125 0.328125 Min 1986-01-27 1987-03-24&lt;BR /&gt;10000 1987-03-25 3893 1 4.4375 0.328125 0.34375 Comparison 1986-01-27 1987-03-24&lt;BR /&gt;10000 1987-03-26 3893 1 4.4375 0.28125 0.28125 Min 1986-01-27 1987-03-26&lt;BR /&gt;10000 1987-03-27 3893 1 4.4375 0.28125 0.28125 Comparison 1986-01-27 1987-03-26&lt;BR /&gt;10000 1987-03-30 3893 1 4.4375 0.28125 0.28125 Comparison 1986-01-27 1987-03-26&lt;BR /&gt;10000 1987-03-31 3893 1 4.4375 0.25 0.25 Min 1986-01-27 1987-03-31&lt;BR /&gt;10000 1987-04-01 3893 1 4.4375 0.234375 0.234375 Min 1986-01-27 1987-04-01&lt;BR /&gt;10000 1987-04-02 3893 1 4.4375 0.234375 0.234375 Comparison 1986-01-27 1987-04-01&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2024 07:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-the-firm-PERMNO-not-classified-again-within-one/m-p/926979#M364825</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-05-04T07:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the firm(PERMNO) not classified again within one month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-the-firm-PERMNO-not-classified-again-within-one/m-p/926980#M364826</link>
      <description>&lt;P&gt;Please write the proper DATA step code around your example data so we know which value belongs to which variable.&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2024 08:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-the-firm-PERMNO-not-classified-again-within-one/m-p/926980#M364826</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-05-04T08:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the firm(PERMNO) not classified again within one month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-the-firm-PERMNO-not-classified-again-within-one/m-p/926981#M364827</link>
      <description>&lt;P&gt;Got it now! thx!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DM'LOG; CLEAR; OUT; CLEAR; ODSRESULTS; CLEAR;';
%LET FOLDER=%STR(C:\USERS\ALAIN\ONEDRIVE\桌面\HIGH);
LIBNAME HIGH "&amp;amp;FOLDER";

DATA HH;
 SET HIGH.HH;
 IF CFACPR=0 THEN DELETE;
RUN;

DATA HH;
	SET	HH;
	IF _N_ &amp;lt;=1000;
RUN;

PROC SORT 
  DATA=HH (KEEP  =SHRCD EXCHCD PERMNO DATE PRC CFACPR SHROUT CFACSHR
                      WHERE =( SHRCD IN (10,11) AND EXCHCD IN (1,2,3,31,32,33) )
                      ) 

OUT=HL(DROP=SHRCD EXCHCD );
  BY PERMNO DATE;
RUN;

DATA HL; 
    SET HL; 
    BY PERMNO DATE; 
    RETAIN H L 0; 
    P=ABS(DIVIDE (PRC, CFACPR));
    IF FIRST.PERMNO THEN H = P; 
    IF FIRST.PERMNO THEN L = P;
    H = MAX(H, P); 
    L = MIN(L, P);
 DROP  PRC CFACPR;
   RUN; /* PERMNO DATE  SHROUT CFACSHR H L P */

data MK (drop=_:);
  set HL;
  BY PERMNO date; 

  retain _first_date_qualified . 
         _H   .                 
         _H_date .              
         _L   .                 
         _L_date .              
          PORTFOLIO 
;             
LENGTH  PORTFOLIO $11;

  if first.permno then do;
    call missing(of _:);
    _first_date_qualified=intnx('year',date,1,'same')+1;
  end;

  if _H=. then _H=P;
  if _L=. then _L=P;

  if P ^=. then do;
    if P &amp;gt; _H and date &amp;gt;= INTNX('MONTH', _H_DATE, 1, 'SAME')) then do;
      _H=P;
      _H_date=date;
      portfolio='Max';
    end;

    else if P &amp;lt; _L and date &amp;gt;= INTNX('MONTH', _L_DATE, 1, 'SAME')) then do;
      _L=P;
      _L_date=date;
      portfolio='Min';
    end;

    else portfolio='Comparison';
  end;

  if date &amp;gt;= _first_date_qualified then do;
      H = _H;
      H_date = _H_date;
      L = _L;
      L_date = _L_date;
  end;

  if date &amp;lt; _first_date_qualified then do;
    portfolio = 'Unqualified';
  end;

  format H_date L_date yymmdd10. ;

run;

DATA MK;
  SET MK(OBS=500);
  PUT (_ALL_) (+0);
RUN;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 May 2024 08:56:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-the-firm-PERMNO-not-classified-again-within-one/m-p/926981#M364827</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-05-04T08:56:47Z</dc:date>
    </item>
  </channel>
</rss>

