BookmarkSubscribeRSS Feed
hellohere
Pyrite | Level 9

I am getting regional maxs/mins where to set reference lines (axis=x). I need show the reference lines with two diff. colors (Max-> Blue; Min -> Cyan).

 

Sample code is below. Used additional dataset is fine, such as _test_mm_ind.

 

Thanks, 

 


data _test;
do i=1 to 300;
	tsvar=sin(i/10); output;
end;
run;quit;

	proc sgplot data=_test(where=(i between 150 and 450));
	series x=i y=tsvar /lineattrs=(color=red thickness=2 pattern=solid);   
	run;quit;

	proc sql noprint;
	select i into: _ref_1 from _test where i between   	10 and   20 having tsvar=max(tsvar);
	select i into: _ref_2 from _test where i between    40 and   60 having tsvar=min(tsvar);
	select i into: _ref_3 from _test where i between   	70 and   90 having tsvar=max(tsvar);
	select i into: _ref_4 from _test where i between   100 and  120 having tsvar=min(tsvar);
	select i into: _ref_5 from _test where i between   130 and  150 having tsvar=max(tsvar);
	select i into: _ref_6 from _test where i between   160 and  180 having tsvar=min(tsvar);
	select i into: _ref_7 from _test where i between   200 and  220 having tsvar=max(tsvar);
	select i into: _ref_8 from _test where i between   220 and  240 having tsvar=min(tsvar);
	select i into: _ref_9 from _test where i between   260 and  280 having tsvar=max(tsvar);
	quit;

	proc sgplot data=_test(where=(i between 00 and 14000));
	series x=i y=tsvar /lineattrs=(color=red thickness=2 pattern=solid); 
	refline  &_ref_1./axis=x lineattrs=(color=blue thickness=2 pattern=solid); 
 	refline  &_ref_2./axis=x;
	refline  &_ref_3./axis=x;
	refline  &_ref_4./axis=x;
	refline  &_ref_5./axis=x;
	refline  &_ref_6./axis=x;
	refline  &_ref_7./axis=x;
	refline  &_ref_8./axis=x;
	refline  &_ref_9./axis=x;
	run;quit;

	%let mvars=&_ref_1.@&_ref_2.@&_ref_3.@&_ref_4.@&_ref_5.@&_ref_6.@&_ref_7.@&_ref_8.@&_ref_9.;
    %let mvars2=max@min@max@min@max@min@max@min@max;

	data _test_mm_ind;
	do i= 1 to countw(symget('mvars'),'@');
		length mm_indx note $8. ;
			mm_indx=scan(symget('mvars'),i,'@');
			note=scan(symget('mvars2'),i,'@');
		output;
	end;
	run;quit;
8 REPLIES 8
PaigeMiller
Diamond | Level 26

Nowhere in your code do you ask for a CYAN colored line. 


This should work, I'm too lazy to fix all of your lines, I only fixed one line, you can fix the rest of the lines as needed.

 

 	refline  &_ref_2./axis=x lineattrs=(color=cyan thickness=2 pattern=solid);

 

 

By the way, it not clear what the data set named _test_mm_ind has to do with anything. You included it without giving an explanation of what it does or why it is important.

--
Paige Miller
hellohere
Pyrite | Level 9

Nice fix.  What if here is 100 max/min?! Close to your daily?! 

quickbluefish
Barite | Level 11

It's next to impossible to tell what you're trying to do here or what question it is that you're asking.  The first DATA step has i from 1 to 300.  Then there's an SGPLOT that reads that dataset from i=150 to 450.  Then there's a SQL step that has inconsistent ranges - some have a gap of 20 between the max of gap(n) and the min of gap(n+1), some have a gap of 10, some have a gap of zero.  That matters because it appears (in the next SGPLOT) that you're planning to extend this to 14000, so really you need a macro, an array solution, or something else to be able to do that in a sane way, and there's no way for anyone to help you without understanding the pattern of the ranges you're looking for.  Then, in the final step, which, like Paige Miller, I am also baffled by, you're reading the macro variables you just created from the first dataset back into another dataset -- is this supposed to be an "annotate" dataset used by SGPLOT?  

PaigeMiller
Diamond | Level 26

I agree with QBF, there are a lot of things in your code and problem statement that either don't make sense, or need a lot more explanation, or raise eyebrows. I'm not at all sure your question is the one I gave a solution for — is the problem really that you want cyan lines but you never told SAS to draw a cyan line? I think it would be a positive thing to re-write this whole problem statement with a goal of making it much clearer. And don't make the mistake of assuming that we know what you are doing or we can figure out what you are doing, because as I said, I have no idea what data set _test_mm_ind is doing or why it is even included.

--
Paige Miller
hellohere
Pyrite | Level 9
sample code .... i need collect the max/min for later macro loop.
Tom
Super User Tom
Super User

Before trying to use macro code and macro variables to generate code make sure you know what code you want to generate.

 

Can you provide a simple example with 2 or three reference lines without any macro variables?

 

Then explain what parts of the code needs to vary.

 

Are you sure you need to use code generation to produce the graph you want?  If you could explain the graph, perhaps include a picture of what you want it look like, then perhaps there is a way to make it directly from a dataset (or multiple datasets) instead.

 

Also can you explain what the graph represents?  Perhaps SAS already has a procedure to produce the graph you want.

hellohere
Pyrite | Level 9
ignore this thread. I started a new one.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 8 replies
  • 358 views
  • 1 like
  • 4 in conversation