BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Irenelee
Obsidian | Level 7

486 IF LAG(FLAG) IN ('Max', 'Min') AND DATE < INTNX('MONTH', LAG(DATE), 1, 'SAME') THEN FLAG = LAG(FLAG);
487 run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
486:6
NOTE: Invalid numeric data, 'Max' , at line 486 column 6.
PERMNO=10000 DATE=1986-01-07 SHROUT=3680 CFACSHR=1 H=2.5625 L=2.5625 P=2.5625 FIRST.PERMNO=1 LAST.PERMNO=0
_first_date_qualified=9869 _H=2.5625 _H_date=. _L=2.5625 _L_date=. portfolio=Unqualified H_date=. L_date=. FLAG=. _ERROR_=1
_N_=1
NOTE: Invalid numeric data, 'Max' , at line 486 column 6.
PERMNO=10000 DATE=1986-01-08 SHROUT=3680 CFACSHR=1 H=2.5625 L=2.5 P=2.5 FIRST.PERMNO=0 LAST.PERMNO=0 _first_date_qualified=9869
_H=2.5625 _H_date=. _L=2.5 _L_date=9504 portfolio=Unqualified H_date=. L_date=. FLAG=. _ERROR_=1 _N_=2
NOTE: Invalid numeric data, 'Max' , at line 486 column 6.
PERMNO=10000 DATE=1986-01-09 SHROUT=3680 CFACSHR=1 H=2.5625 L=2.5 P=2.5 FIRST.PERMNO=0 LAST.PERMNO=0 _first_date_qualified=9869
_H=2.5625 _H_date=. _L=2.5 _L_date=9504 portfolio=Unqualified H_date=. L_date=. FLAG=. _ERROR_=1 _N_=3
NOTE: Invalid numeric data, 'Max' , at line 486 column 6.
PERMNO=10000 DATE=1986-01-10 SHROUT=3680 CFACSHR=1 H=2.5625 L=2.5 P=2.5 FIRST.PERMNO=0 LAST.PERMNO=0 _first_date_qualified=9869
_H=2.5625 _H_date=. _L=2.5 _L_date=9504 portfolio=Unqualified H_date=. L_date=. FLAG=. _ERROR_=1 _N_=4
NOTE: Invalid numeric data, 'Max' , at line 486 column 6.
PERMNO=10000 DATE=1986-01-13 SHROUT=3680 CFACSHR=1 H=2.625 L=2.5 P=2.625 FIRST.PERMNO=0 LAST.PERMNO=0
_first_date_qualified=9869 _H=2.625 _H_date=9509 _L=2.5 _L_date=9504 portfolio=Unqualified H_date=. L_date=. FLAG=. _ERROR_=1
_N_=5
NOTE: Invalid numeric data, 'Max' , at line 486 column 6.
PERMNO=10000 DATE=1986-01-14 SHROUT=3680 CFACSHR=1 H=2.75 L=2.5 P=2.75 FIRST.PERMNO=0 LAST.PERMNO=0 _first_date_qualified=9869
_H=2.75 _H_date=9510 _L=2.5 _L_date=9504 portfolio=Unqualified H_date=. L_date=. FLAG=. _ERROR_=1 _N_=6
NOTE: Invalid numeric data, 'Max' , at line 486 column 6.
PERMNO=10000 DATE=1986-01-15 SHROUT=3680 CFACSHR=1 H=2.875 L=2.5 P=2.875 FIRST.PERMNO=0 LAST.PERMNO=0
_first_date_qualified=9869 _H=2.875 _H_date=9511 _L=2.5 _L_date=9504 portfolio=Unqualified H_date=. L_date=. FLAG=. _ERROR_=1
_N_=7
NOTE: Invalid numeric data, 'Max' , at line 486 column 6.
PERMNO=10000 DATE=1986-01-16 SHROUT=3680 CFACSHR=1 H=3 L=2.5 P=3 FIRST.PERMNO=0 LAST.PERMNO=0 _first_date_qualified=9869 _H=3
_H_date=9512 _L=2.5 _L_date=9504 portfolio=Unqualified H_date=. L_date=. FLAG=. _ERROR_=1 _N_=8
NOTE: Invalid numeric data, 'Max' , at line 486 column 6.

Irenelee
Obsidian | Level 7
thx!!

DM'LOG; CLEAR; OUT; CLEAR; ODSRESULTS; CLEAR;';
%LET FOLDER=%STR(C:\USERS\ALAIN\ONEDRIVE\桌面\HIGH);
LIBNAME HIGH "&FOLDER";

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 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;

RETAIN _FIRST_DATE_QUALIFIED .
_H .
_H_DATE .
_L .
_L_DATE .
PORTFOLIO $11. ;

IF FIRST.PERMNO THEN DO;
CALL MISSING(OF _:);
_FIRST_DATE_QUALIFIED=INTNX('YEAR', DATE, 1, 'SAME')+1;
PORTFOLIO = ' ';
END;

IF _H=. THEN _H=P;
IF _L=. THEN _L=P;

IF P ^=. THEN DO;
IF P > _H AND NOT (PORTFOLIO='MAX' AND DATE < INTNX('MONTH', _H_DATE, 1, 'SAME')) THEN DO;
_H=P;
_H_DATE=DATE;
PORTFOLIO='MAX';
END;
ELSE IF P < _L AND NOT (PORTFOLIO='MIN' AND DATE < INTNX('MONTH', _L_DATE, 1, 'SAME')) THEN DO;
_L=P;
_L_DATE=DATE;
PORTFOLIO='MIN';
END;
END;

IF DATE >= _FIRST_DATE_QUALIFIED THEN DO;
H=_H;
H_DATE=_H_DATE;
L=_L;
L_DATE=_L_DATE;
IF PORTFOLIO=' ' THEN PORTFOLIO='COMPARISON';
END;
ELSE PORTFOLIO='UNQUALIFIED';

FORMAT H_DATE L_DATE YYMMDD10. ;
RUN;

DATA MK;
SET MK(OBS=2000);
PUT (_ALL_) (+0);
RUN;
Irenelee
Obsidian | Level 7
Highs(highest closing price ever seen) should be recorded Once per PERMNO for every new historic high. I want one observation per day in my output dataset. For every observation, rolling everyday. Because i want to record historical high price every day, it may change or not everyday. NVDA created its new historical high very often since last year.
Irenelee
Obsidian | Level 7

May I know how to correct the following error?  ERROR 161-185: No matching DO/SELECT statement.

27 DATA FLAG;
28 SET HL;
29 BY PERMNO DATE;
30 retain FLAG;
31 if first.permno then do;
32 counter = 0;
33 first_date = date;
34 end;
35 day_of_year = intnx('day', date, first_date);
36 if day_of_year <= 365 and not missing(day_of_year) then FLAG = 'UNQUALIFIED';
37
38 if PRC > LAG(H) AND date >= '01JAN1963'd then FLAG = MAX;
39 if PRC < LAG(L) AND date >= '01JAN1963'd then FLAG = MIN;
40 else FLAG = COMPARISON;
41 end;
---
161
ERROR 161-185: No matching DO/SELECT statement.

Irenelee
Obsidian | Level 7

What we define "break through the historical high", excluding the data that is less than one year. Otherwise,  only two days after the IPO continuing to create new highs that is not my definition of breaking through the historical high.

In addition, since we need to calculate the one-month return after breaking through the historical high/low, the group that is classified as breaking through the historical high/low must wait another month before it can be classified as the breaking through the historical high group again, because it has already been included in the breaking through the historical high/low group, it will not be classified again.

 

 

 

Irenelee
Obsidian | Level 7

Closing Price or Bid/Ask Average
Variable Name = PRC

PRC is the closing price or the negative bid/ask average for a trading day. If the closing price is not available on any given trading day, the number in the price field has a negative sign to indicate that it is a bid/ask average and not an actual closing price. Please note that in this field the negative sign is a symbol and that the value of the bid/ask average is not negative.

If neither closing price nor bid/ask average is available on a date, PRC is set to zero. In a monthly database, prc is the price on the last trading date of the month. The price series begins the first month-end after the security begins trading and ends the last complete month of trading.

If the security of a company is included in the Composite Pricing network, the closing price while listed on NYSE or AMEX on a trading date is the last trading price for that day on the exchange that the security last traded.

Irenelee
Obsidian | Level 7

If the security of a company is included in the Composite Pricing network, the closing price while listed on NYSE or AMEX on a trading date is the last trading price for that day on the exchange that the security last traded.

Similarly, highs, lows, and volumes include trades on all exchanges on which that security traded. For example, if a stock trades on both the NYSE and the PACX (Pacific Stock Exchange), and the last trade occurs on the PACX, the closing price on that day represents the closing price on the PACX, not the NYSE. Price data for Nasdaq securities comes directly from the NASD with the close of the day at 4:00 p.m. Eastern Time. Automated trades after hours on Nasdaq are counted on the next trading date, although the volumes are applied to the current date. Daily trading prices for The Nasdaq National Market securities were first reported November 1, 1982. Daily trading prices for The Nasdaq Small Cap Market were first reported June 15, 1992. prc for Nasdaq securities is always a negative bid/ask average before this time. All prices are raw prices as they were reported at the time of trading.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 36 replies
  • 660 views
  • 4 likes
  • 4 in conversation