May I know why Variable HH is uninitialized? Thx!
I want to FLAG BREAK UP THROUGH HISTORICAL HIGH (THE FIRST PORTFOLIO MAX ) : IF THAT FIRM-DATE’S PRICE> HISTORICAL HIGH PRICE AND THE NEW FLAG HAVE TO PASS THROUGH ONE MONTH
DATA HHLL;
SET HH;
BY PERMNO DATE;
HH=MAX(ABS(PRC/CFACPR),HH);
LL=MIN(ABS(PRC/CFACPR),LL);
IF FIRST.PERMNO THEN HH = .;
IF FIRST.PERMNO THEN LL = .;
RETAIN HH LL;
END;
RUN;
DATA HHLL1;
SET HHLL;
WHERE DATE BETWEEN '01JAN1963'D and '31DEC2023'D;
RUN;
DATA FLAG;
SET HHLL1;
BY PERMNO;
RETAIN FLAG;
IF FIRST.PERMNO THEN FLAG = .;
IF DATE > INTNX('MONTH', FLAG, 1) THEN DO;
IF PRC > HH THEN FLAG = 'MAX';
ELSE IF PRC < LL THEN FLAG = 'MIN';
ELSE FLAG = 'COMPARISON';
RUN;
The line
LL=MIN(ABS(PRC/CFACPR),LL);
has one logic problem: LL is missing in the first iteration. Missing is always smaller than anything else, so LL stays missing.
@andreas_lds wrote:
The line
LL=MIN(ABS(PRC/CFACPR),LL);
has one logic problem: LL is missing in the first iteration. Missing is always smaller than anything else, so LL stays missing.
MIN function ignores missing values, so this is not the problem. e.g.:
1 data _null_ ; 2 put x= ; 3 x=min(x,2) ; 4 put x= ; 5 run ; x=. x=2
Sry, I do not know what do u mean by
1 data _null_ ; 2 put x= ; 3 x=min(x,2) ; 4 put x= ; 5 run ; x=. x=2
^^
90 DATA FLAG;
91 SET HHLL1;
92 BY PERMNO;
93 RETAIN FLAG;
94 IF FIRST.PERMNO THEN FLAG = .;
95 IF DATE > INTNX('MONTH', FLAG, 1) THEN DO;
96 IF PRC > HH THEN FLAG = 'MAX';
97 ELSE IF PRC < LL THEN FLAG = 'MIN';
98 ELSE FLAG = 'COMPARISON';
99 RUN;
99 RUN;
-
117
ERROR 117-185: There 是 1 個未封閉的 DO 區塊.
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
96:33 97:39 98:21
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.FLAG may be incomplete. When this step was stopped there were 0 observations and 13
variables.
WARNING: 未取代資料集 WORK.FLAG,因為 this step was stopped.
NOTE: DATA 陳述式 used (Total process time):
real time 0.00 秒
cpu time 0.01 秒
Thank you ,How may I create a new Column named HH which is a firm’s historical high price till yesterday.(every line we have a firm’s id PERMNO, date, close price) vice versa LL
That log is showing that you have values of 0 for the variable CFACPR.
Division by 0 results in invalid data. If those values are indeed supposed to be 0 what do you expect as a result for the division involved? The result of the division will be missing and so if the other value is also missing you get a missing value for the result. Enough of those and the variable HH or LL is uninitialized.
You can use the DIVIDE function to remove the messages from the log but you still get missing for the result.
ABS( divide (PRC, CFACPR))
At this point I am going to say that without a working example of your input data set HH I can't actually help any further.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... 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 </> icon or attached as text to show exactly what you have and that we can test code against.
Are you getting an "uninitialized" message from SAS? If so, you need to show us the log so we have a chance of telling which of the two data steps using the variable HH is involved.
After that we may have some things to investigate.
What the table I want to create is as below but by historical high, instead of 52 weeks high.
but I'm trapped here
130 DATA HHLL;
131 SET HH;
132 BY PERMNO DATE;
133 HH=MAX(ABS(PRC/CFACPR),HH);
134 LL=MIN(ABS(PRC/CFACPR),LL);
135 IF FIRST.PERMNO THEN HH = .;
136 IF FIRST.PERMNO THEN LL = .;
137 RETAIN HH LL;
138 RUN;
NOTE: Division by zero detected at 行 133 欄 16.
Without example data I cannot tell how your code is related to the table.
You have issues with division by 0.
Have you checked why those values are 0?
Are they supposed to be zero?
What result should a 0 yield instead of missing, if you expect such.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.