<?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 make sure at least 1 year of available daily price data exist in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/925955#M364359</link>
    <description>&lt;P&gt;Thank you team,&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="appearance.JPG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95916iC94A7ADA177B76D8/image-size/large?v=v2&amp;amp;px=999" role="button" title="appearance.JPG" alt="appearance.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;OL&gt;&lt;LI&gt;How may SAS code create a new Column named “H” which is a firm’s historical high price? (every line we have a firm’s id PERMNO, date, close price) vice versa “L”&lt;/LI&gt;&lt;LI&gt;How may SAS code create a new Column named “HH” which HH=LAG(H), BUT FIRST YEAR'S PERMNO’s daily HH=INFINITE. (the price have to exist more than one year, for example 1963/1/1’s historical high price have to be have price exsit from 1962/1/1. Because I want to make sure at least 1 year of available daily price data, which is required to be defined historical high stock price may be compared with the 52-week period range.&lt;/LI&gt;&lt;/OL&gt;</description>
    <pubDate>Fri, 26 Apr 2024 06:39:21 GMT</pubDate>
    <dc:creator>Irenelee</dc:creator>
    <dc:date>2024-04-26T06:39:21Z</dc:date>
    <item>
      <title>make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/925955#M364359</link>
      <description>&lt;P&gt;Thank you team,&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="appearance.JPG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95916iC94A7ADA177B76D8/image-size/large?v=v2&amp;amp;px=999" role="button" title="appearance.JPG" alt="appearance.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;OL&gt;&lt;LI&gt;How may SAS code create a new Column named “H” which is a firm’s historical high price? (every line we have a firm’s id PERMNO, date, close price) vice versa “L”&lt;/LI&gt;&lt;LI&gt;How may SAS code create a new Column named “HH” which HH=LAG(H), BUT FIRST YEAR'S PERMNO’s daily HH=INFINITE. (the price have to exist more than one year, for example 1963/1/1’s historical high price have to be have price exsit from 1962/1/1. Because I want to make sure at least 1 year of available daily price data, which is required to be defined historical high stock price may be compared with the 52-week period range.&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Fri, 26 Apr 2024 06:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/925955#M364359</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-04-26T06:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/925956#M364360</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;DATA HHLL;
 SET HH;
 BY PERMNO DATE;
 retain OHH HH;
 OHH = max(ABS( divide (PRC, CFACPR)));
 HH=LAG(OHH);
 IF FIRST.PERMNO THEN OHH = ABS( divide (PRC, CFACPR));
 else if ABS( divide (PRC, CFACPR))  &amp;gt; OHH then OHH = ABS( divide (PRC, CFACPR);
  RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Apr 2024 06:40:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/925956#M364360</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-04-26T06:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/925967#M364366</link>
      <description>&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Provide an example of your data and what you expect the result for that sample to look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I want the maximum value of something across all the data the easiest is Proc Means/summary.&lt;/P&gt;
&lt;PRE&gt;Proc summary data=hh ;
   by permno;
   var &amp;lt;name of variable with price&amp;gt;;&lt;BR /&gt;   output out=temp max= H min=L ;
run;
&lt;/PRE&gt;
&lt;P&gt;Merge that back onto the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I cannot tell what&amp;nbsp; that second bit means. If you mean a "rolling" maximum, meaning each week you need the maximum for the previous 52 weeks that is a bit complicated. If you mean the Max (or min or whatever) for a calendar year that may be relatively easy but your bit of "52 weeks" is a tad awkward to deal with from daily data without a concrete example. One year and 52 weeks are not exactly the same as there are 52.143 or 52.286 7 day periods within a calendar year. "Week" definitions are also a bit tricky because they depend on which day to start and how to count things at calendar year boundaries. So you need to work through with some actual example what you expect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And your code example makes no sense in either context plus the examples in your other posts with division by zero that you seem not to understand that you need to provide what to do when such would occur. Something like&lt;/P&gt;
&lt;PRE&gt;If &amp;lt;variable&amp;gt; ne 0 then  &amp;lt;the code that uses the division&amp;gt;; 
else &amp;lt;some code that makes sense in terms of the problem when the variable is zero&amp;gt;;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 08:59:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/925967#M364366</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-04-26T08:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926145#M364440</link>
      <description>&lt;P&gt;Thx!&lt;BR /&gt;&lt;BR /&gt;sample data is as the following&lt;/P&gt;&lt;P&gt;&lt;A href="https://drive.google.com/file/d/1DAPXaUmE5xKvJmnfV7vz-MVF9MGVfSDk/view" target="_blank"&gt;https://drive.google.com/file/d/1DAPXaUmE5xKvJmnfV7vz-MVF9MGVfSDk/view&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;expect the result for that sample to look like the following&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Irenelee_0-1714221811455.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95971i16C858C9B7565038/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Irenelee_0-1714221811455.png" alt="Irenelee_0-1714221811455.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 12:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926145#M364440</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-04-27T12:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926148#M364441</link>
      <description>&lt;P&gt;Thx!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data I have looks like the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="data.JPG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95973i08DEB6A71C3C9D79/image-size/large?v=v2&amp;amp;px=999" role="button" title="data.JPG" alt="data.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 12:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926148#M364441</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-04-27T12:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926151#M364443</link>
      <description>&lt;OL&gt;&lt;LI&gt;How may SAS code create a new Column named “H” which is a firm’s daily rolling historical high price? (every line we have a firm’s id PERMNO, date, close price) vice versa “L”&lt;/LI&gt;&lt;LI&gt;How may SAS code create a new Column named FLAG.&lt;UL&gt;&lt;LI&gt;The price of a firm by that date &amp;gt; LAG(H), then classified into “Max” portfolio&lt;/LI&gt;&lt;LI&gt;vice versa “Min”&lt;/LI&gt;&lt;LI&gt;The remaining classified into third portfolio flagged “COMPARISON”&lt;/LI&gt;&lt;LI&gt;But a firm only flagged after a year by IPO. for example, a firm may only start to be classified after 1963/1/1, if this firm is IPOed on 1962/1/1. So these firms can only classified “unqualified” for the first year after IPO.&lt;/LI&gt;&lt;LI&gt;Because we will watch the monthly return after the stock is classified into Max or Min portfolio, so the same stock can not be reclassified into Max or Min within one month after it was classified into Max or Min. &amp;nbsp;for example, if a firm is classified into “Max” on 1963/1/1, then this firm can only classified into “Max” again after 1963/2/1.&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="looklike.JPG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95974i64BDF31CA4F3CC6B/image-size/large?v=v2&amp;amp;px=999" role="button" title="looklike.JPG" alt="looklike.JPG" /&gt;&lt;/span&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Sat, 27 Apr 2024 13:07:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926151#M364443</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-04-27T13:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926162#M364451</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465079"&gt;@Irenelee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thx!&lt;BR /&gt;&lt;BR /&gt;sample data is as the following&lt;/P&gt;
&lt;P&gt;&lt;A href="https://drive.google.com/file/d/1DAPXaUmE5xKvJmnfV7vz-MVF9MGVfSDk/view" target="_blank" rel="noopener"&gt;https://drive.google.com/file/d/1DAPXaUmE5xKvJmnfV7vz-MVF9MGVfSDk/view&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;expect the result for that sample to look like the following&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Irenelee_0-1714221811455.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95971i16C858C9B7565038/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Irenelee_0-1714221811455.png" alt="Irenelee_0-1714221811455.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That file on google drive is over 200 megabytes. Google even says it is too large to scan for viruses. So why should I download something that is that big.&lt;/P&gt;
&lt;P&gt;Subset your data to maybe 2 values of Permno and associated stuff. Then post that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I still have no idea what actual rules are involved. I do see a magic word "Rolling". Which means as a minimum you need to very clearly describe what period is involved with "rolling" what value is returned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am starting to think that picture of what appears to be a report template of some sort needs some serious expansion as to what MAX means. I see text like "MAX(if prc&amp;gt;HH)". What does that mean in some details. It most programming environments "if prc&amp;gt;hh" is a boolean (logical) expression and returns true/false or numerically 1/0. So "MAX" of an expression that is true/false looks weird.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pick a specified set of observations. Calculate the results. Describe the calculations you have done to get the desired result and show that desired result, as in actual numbers, given that example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 16:32:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926162#M364451</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-04-27T16:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926164#M364453</link>
      <description>&lt;P&gt;what i try is as below&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA HH;
	SET	HIGH.HH;
	IF CFACPR=0 THEN DELETE;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;
 H = max(ABS( divide (PRC, CFACPR)));
 L = min(ABS( divide (PRC, CFACPR)));
 RUN;

DATA FLAG;
 SET HL;
 BY PERMNO DATE;
 retain FLAG;
  if first.permno then do;
	counter = 0;
	first_date = date; 
  end;
	day_of_year = intnx('day', date, first_date);
  if day_of_year &amp;lt;= 365 and not missing(day_of_year) then FLAG = 'UNQUALIFIED';

 if PRC &amp;gt; LAG(H) AND date &amp;gt;= '01JAN1963'd then FLAG = MAX; 
 if PRC &amp;lt; LAG(L) AND date &amp;gt;= '01JAN1963'd then FLAG = MIN; 
 else FLAG = COMPARISON;
 end;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Apr 2024 16:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926164#M364453</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-04-27T16:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926165#M364454</link>
      <description>&lt;P&gt;Photographs of data are impossible to program from. And they hide all kinds of relevant information about the data (is the variable numeric or character? Does it have a display format attached? Which format?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You appear to have data in SAS already.&amp;nbsp; So it is TRIVIAL to copy it out as TEXT.&amp;nbsp; For example to get the first 10 observations you might do something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set have(obs=10);
  put (_all_) (+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then just copy the space delimited text from the SAS log.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 16:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926165#M364454</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-27T16:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926166#M364455</link>
      <description>&lt;P&gt;How may SAS code create a new Column named FLAG.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;tag the daily price data of its first day to 365th day to the flag of UNQUALIFIED&lt;BR /&gt;for example, &amp;nbsp;if a firm is IPOed on 1962/10/1, this firm can only be classified “unqualified” for the 1962/10/1 to 1963/10/1.&lt;/LI&gt;&lt;LI&gt;The price of a firm by that date &amp;gt; LAG(H), then classified into “Max” portfolio after 1963/1/1, vice versa “Min”&lt;/LI&gt;&lt;LI&gt;The remaining classified into “COMPARISON"&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 16:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926166#M364455</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-04-27T16:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926168#M364456</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="data.JPG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95976i315FAFC7B411AC07/image-size/large?v=v2&amp;amp;px=999" role="button" title="data.JPG" alt="data.JPG" /&gt;&lt;/span&gt;Because we will watch the monthly return after the stock is classified into Max or Min portfolio, so the same stock can not be reclassified into Max or Min within one month after it was classified into Max or Min. &amp;nbsp;for example, if a firm is classified into “Max” on 1963/1/1, then this firm can only classified into “Max” again after 1963/2/1.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 16:45:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926168#M364456</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-04-27T16:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926169#M364457</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465079"&gt;@Irenelee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;OL&gt;
&lt;LI&gt;How may SAS code create a new Column named “H” which is a firm’s historical high price? (every line we have a firm’s id PERMNO, date, close price) vice versa “L”&lt;/LI&gt;
&lt;LI&gt;How may SAS code create a new Column named “HH” which HH=LAG(H), BUT FIRST YEAR'S PERMNO’s daily HH=INFINITE. (the price have to exist more than one year, for example 1963/1/1’s historical high price have to be have price exsit from 1962/1/1. Because I want to make sure at least 1 year of available daily price data, which is required to be defined historical high stock price may be compared with the 52-week period range.&lt;/LI&gt;
&lt;/OL&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To create the highest value every seen for a "firm" just make a NEW variable and RETAIN it.&amp;nbsp; Change the value when the price goes up.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by firm;
  retain H L ;
  h= max(h,price);
  l = min(l,price);
  if first.firm then do;
     h=price; l=price;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The second description is too confusing to program from.&amp;nbsp; If the point is to remember WHEN the H and L price occurred then remember that also.&amp;nbsp; In which case the programming gets a little more complicated.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by firm;
  retain H L H_date L_date;
  format h_date l_date date9.;
  if first.firm then do;
   h=price; h_date=date;
   l=price; l_date=date;
 end;
 else do ;
   if h&amp;lt;price then do; h=price; h_date=date; end;
   if l &amp;gt; price then do; l=price; l_date=date; run;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can now test on any date how long it has been since the most recent high occured.&lt;/P&gt;
&lt;P&gt;Whether or not that is what you are looking for I have NO idea.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 16:53:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926169#M364457</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-27T16:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926170#M364458</link>
      <description>&lt;P&gt;THX!&lt;/P&gt;&lt;PRE class=""&gt;&lt;CODE&gt; format h_date l_date date9.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;May I ignore this format setting? and just use original date ?&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 16:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926170#M364458</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-04-27T16:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926171#M364459</link>
      <description>&lt;P&gt;10000 1986-01-07 -2.56250 3680 1 1 2.5625 2.5625&lt;BR /&gt;10000 1986-01-08 -2.50000 3680 1 1 2.5 2.5&lt;BR /&gt;10000 1986-01-09 -2.50000 3680 1 1 2.5 2.5&lt;BR /&gt;10000 1986-01-10 -2.50000 3680 1 1 2.5 2.5&lt;BR /&gt;10000 1986-01-13 -2.62500 3680 1 1 2.625 2.625&lt;BR /&gt;10000 1986-01-14 -2.75000 3680 1 1 2.75 2.75&lt;BR /&gt;10000 1986-01-15 -2.87500 3680 1 1 2.875 2.875&lt;BR /&gt;10000 1986-01-16 -3.00000 3680 1 1 3 3&lt;BR /&gt;10000 1986-01-17 -3.00000 3680 1 1 3 3&lt;BR /&gt;10000 1986-01-20 -3.00000 3680 1 1 3 3&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 16:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926171#M364459</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-04-27T16:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926172#M364460</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465079"&gt;@Irenelee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;THX!&lt;/P&gt;
&lt;PRE class=""&gt;&lt;CODE&gt; format h_date l_date date9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;May I ignore this format setting? and just use original date ?&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you don't attach a date type display format to the new variables then the raw number of days since 1960 will be printed.&amp;nbsp; That will be hard for humans to understand.&amp;nbsp; You can attach any of the dozens of formats that format date values.&amp;nbsp; If you want the dates to look like 2024-04-27 then use yymmdd10. as the format specification in the FORMAT statement.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 17:01:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926172#M364460</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-27T17:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926173#M364461</link>
      <description>&lt;P&gt;it seems date already printed easily to be understood for the moment, right? So I may omit the process of the date format?&lt;/P&gt;&lt;P&gt;691 data HL;&lt;BR /&gt;692 set HL(obs=10);&lt;BR /&gt;693 put (_all_) (+0);&lt;BR /&gt;694 run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;10000 1986-01-07 -2.56250 3680 1 1 2.5625 2.5625&lt;BR /&gt;10000 1986-01-08 -2.50000 3680 1 1 2.5 2.5&lt;BR /&gt;10000 1986-01-09 -2.50000 3680 1 1 2.5 2.5&lt;BR /&gt;10000 1986-01-10 -2.50000 3680 1 1 2.5 2.5&lt;BR /&gt;10000 1986-01-13 -2.62500 3680 1 1 2.625 2.625&lt;BR /&gt;10000 1986-01-14 -2.75000 3680 1 1 2.75 2.75&lt;BR /&gt;10000 1986-01-15 -2.87500 3680 1 1 2.875 2.875&lt;BR /&gt;10000 1986-01-16 -3.00000 3680 1 1 3 3&lt;BR /&gt;10000 1986-01-17 -3.00000 3680 1 1 3 3&lt;BR /&gt;10000 1986-01-20 -3.00000 3680 1 1 3 3&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 17:06:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926173#M364461</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-04-27T17:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926174#M364462</link>
      <description>&lt;P&gt;Great. So the next step is to take that text and convert it into a SAS program that you can share so anyone that wants to help you can have your data.&lt;/P&gt;
&lt;P&gt;Not sure what your variable names are but perhaps something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input firm $ date :yymmdd. price volume a b c d ;
  format date yymmdd10.;
cards;
10000 1986-01-07 -2.56250 3680 1 1 2.5625 2.5625
10000 1986-01-08 -2.50000 3680 1 1 2.5 2.5
10000 1986-01-09 -2.50000 3680 1 1 2.5 2.5
10000 1986-01-10 -2.50000 3680 1 1 2.5 2.5
10000 1986-01-13 -2.62500 3680 1 1 2.625 2.625
10000 1986-01-14 -2.75000 3680 1 1 2.75 2.75
10000 1986-01-15 -2.87500 3680 1 1 2.875 2.875
10000 1986-01-16 -3.00000 3680 1 1 3 3
10000 1986-01-17 -3.00000 3680 1 1 3 3
10000 1986-01-20 -3.00000 3680 1 1 3 3
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Make sure to use the menu items that give up pop-up windows to enter/edit the text for your program (Insert SAS Program) or other text (Insert Code).&amp;nbsp; Otherwise the forum will think you meant that as paragraphs of text to be reflowed to fit the viewers browser window size.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 17:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926174#M364462</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-27T17:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926175#M364463</link>
      <description>&lt;P&gt;Thx!&lt;BR /&gt;Do you know why No matching DO/SELECT statement&lt;BR /&gt;ERROR 161-185: No matching DO/SELECT statement.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA FLAG;
 SET HL;
 BY PERMNO DATE;
 retain FLAG;
  if first.permno then do;
	counter = 0;
	first_date = date; 
  end;
	day_of_year = intnx('day', date, first_date);
  if day_of_year &amp;lt;= 365 and not missing(day_of_year) then FLAG = 'UNQUALIFIED';

 if PRC &amp;gt; LAG(H) AND date &amp;gt;= '01JAN1963'd then FLAG = MAX; 
 if PRC &amp;lt; LAG(L) AND date &amp;gt;= '01JAN1963'd then FLAG = MIN; 
 else FLAG = COMPARISON;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 17:21:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926175#M364463</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-04-27T17:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926176#M364464</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;DATA HH;
	SET	HIGH.HH;
	IF CFACPR=0 THEN DELETE;
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;
 H = max(ABS( divide (PRC, CFACPR)));
 L = min(ABS( divide (PRC, CFACPR)));
 RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Apr 2024 17:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926176#M364464</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-04-27T17:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: make sure at least 1 year of available daily price data exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926177#M364465</link>
      <description>variable names are&lt;BR /&gt;PERMNO DATE PRC CFACPR SHROUT CFACSHR H L</description>
      <pubDate>Sat, 27 Apr 2024 17:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-sure-at-least-1-year-of-available-daily-price-data-exist/m-p/926177#M364465</guid>
      <dc:creator>Irenelee</dc:creator>
      <dc:date>2024-04-27T17:24:37Z</dc:date>
    </item>
  </channel>
</rss>

