Sas 按组控制行颜色/where子句

Sas 按组控制行颜色/where子句,sas,sgplot,Sas,Sgplot,我想用X绘制Y图,其中我按年份分组,但颜色代码基于不同的变量(干)。因此,每年显示为单独的线,但干燥=1年绘制一种颜色,干燥=0年绘制不同的颜色。我实际上想出了一个选择(是的!),如下所示。但这并没有给我多少控制权 有没有办法在series语句中放置where子句来选择特定的类别,以便我可以指定特定的颜色(或其他格式)?还是有别的办法?这类似于R,其中可以对不同的数据子集使用多行语句 谢谢 这个代码有效 proc sgplot data = tmp; where microsite_i

我想用X绘制Y图,其中我按年份分组,但颜色代码基于不同的变量(干)。因此,每年显示为单独的线,但干燥=1年绘制一种颜色,干燥=0年绘制不同的颜色。我实际上想出了一个选择(是的!),如下所示。但这并没有给我多少控制权

有没有办法在series语句中放置where子句来选择特定的类别,以便我可以指定特定的颜色(或其他格式)?还是有别的办法?这类似于R,其中可以对不同的数据子集使用多行语句

谢谢

这个代码有效

proc sgplot data = tmp;  
   where microsite_id = "&msit";
   by microsite_id ;
   yaxis label= "Pct. Stakes" values = (0 to 100 by 20);
   xaxis label= 'Date'  values = (121 to 288 by 15);
   series y=tpctwett x=jday / markers markerattrs=(symbol=plus) group = year grouplc=dry groupmc=dry;
   format jday tadjday metajday jdyfmt.;
   label tpctwett='%surface water' tadval1='breed' metaval1='meta';
run; 

使用属性映射,请参见

您可以使用DRY变量设置特定颜色。对于每年,在数据步骤中使用DRY变量指定颜色

 proc sort data=tmp out=attr_data; by year; run;

 data attrs;
 set attr_data;
 id='year';
 if dry=0 then linecolor='green';
 if dry=1 then  linecolor='red';
 keep id linecolor;
 run;
然后在PROC SGPLOT语句中添加
dattrmap=attrs
,在SGPLOT选项中添加attrid=year

ods graphics / attrpriority=none;

proc sgplot data = tmp dattrmap=attrs;  
where microsite_id = "&msit";
by microsite_id ;
yaxis label= "Pct. Stakes" values = (0 to 100 by 20);
xaxis label= 'Date'  values = (121 to 288 by 15);
series y=tpctwett x=jday / markers markerattrs=(symbol=plus) group = year grouplc=dry groupmc=dry attrid=year;
format jday tadjday metajday jdyfmt.;
label tpctwett='%surface water' tadval1='breed' metaval1='meta';
run; 
请注意,我测试并编辑了这篇文章,所以它现在应该可以工作了