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

Hi Everyone,

 

I have an issue with the result produced by the below loop code.

Basically, when body_50 =1 bar[i], then look forward when condition: new row's low[j] < low[i] + add_level_1[i] then mark:

1 - entry_time = time[j]

2 - entry_price =ceil(low[i] * 100) / 100+ add_level_1[i]

 

As shown in the picture attached, on the row 9:27, body_1 =1 with low[i] + add_level_1[i] = 231.13 and SAS starts look forward.

BUT it pick row 9:30 where low is 131.50 which is bigger than 231.13. It means the condition is Not met and somehow SAS still pick that row.

 

Any help is very much appreciated.

 

Thanks,

HHC

 

hhchenfx_2-1749665548842.png

 


proc sort data=ss; by tic date clock_time;run;

data ss1; set ss nobs=nobs;
drop i j_: out ;
format entry_time bigbar time9.;
i+1;
out=0;
by tic;
if  body_50=1 then do; 
	do j=i+1 to nobs until (out=1);
	set ss (keep=tic date clock_time low high rename = (tic=J_tic date=J_date clock_time=J_clock_time low=J_low high=J_high) ) point=j;

			low_plus_add_level_1=low+add_level_1 ;
			gap=(J_clock_time - clock_time) / 60;

	if date^=J_date or tic^=J_tic or J_clock_time>'15:30't then do; out=1; leave; end;
	else
	if gap<20 and J_low<=low+add_level_1 then do;
		 	entry_time=J_clock_time;
			entry_price=ceil(low * 100) / 100+ add_level_1;
			bigbar=clock_time;
			out=1; leave;
			end;
	else 
	if gap<60 and J_low<=low+add_level_3 then do;
		 	entry_time=J_clock_time;
			entry_price=ceil(low * 100) / 100+ add_level_3;
			bigbar=clock_time;
			out=1; leave;
			end;
	else 
	if gap<120 and J_low<=low+add_level_4 then do;
		 	entry_time=J_clock_time;
			entry_price=ceil(low * 100) / 100+ add_level_4;
			bigbar=clock_time;
			out=1; leave;
			end;
	else 
	if gap<180 and J_low<=low+add_level_5 then do;
		 	entry_time=J_clock_time;
			entry_price=ceil(low * 100) / 100+ add_level_5;
			bigbar=clock_time;
			out=1; leave;
			end;
	else 
	if gap>=180 and J_low<= low +add_level_6 then do;
			entry_time=J_clock_time;
			entry_price=ceil(low * 100) / 100+ add_level_6;
			bigbar=clock_time;
			out=1; leave;
			end;
end;
end;
run;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
hhchenfx
Rhodochrosite | Level 12

Hi Tom,

Thanks for checking.

I found the issue. 

HHC

	if gap<60 then do;
			if J_low<=low+add_level_3 then do;
			 	entry_time=J_clock_time;
				entry_price=ceil(low * 100) / 100+ add_level_3;
				bigbar=clock_time;
				out=1; leave;
				end;end;
	else 
	if gap<120 then do;
			if J_low<=low+add_level_4 then do;
			 	entry_time=J_clock_time;
				entry_price=ceil(low * 100) / 100+ add_level_4;
				bigbar=clock_time;
				out=1; leave;
				end;end;
	else 

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

I do not understand what the LEAVE statements are for.  What is it that you want to LEAVE?

hhchenfx
Rhodochrosite | Level 12

Hi Tom,

Thanks for checking.

I found the issue. 

HHC

	if gap<60 then do;
			if J_low<=low+add_level_3 then do;
			 	entry_time=J_clock_time;
				entry_price=ceil(low * 100) / 100+ add_level_3;
				bigbar=clock_time;
				out=1; leave;
				end;end;
	else 
	if gap<120 then do;
			if J_low<=low+add_level_4 then do;
			 	entry_time=J_clock_time;
				entry_price=ceil(low * 100) / 100+ add_level_4;
				bigbar=clock_time;
				out=1; leave;
				end;end;
	else 
Tom
Super User Tom
Super User

Still don't understand why you have both the LEAVE and the UNTIL().

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 597 views
  • 2 likes
  • 2 in conversation