Hi guys,
I was able to draw a series plot in SAS IML with the following code, however, the YAXIS is automatically starting at 0.4. I want it to range from 0 to 1 instead. After some searching, I found that the command plot.SetAxisViewRange (YAXIS, 0, 1) would this, but it's not working for me, I get the error message: "ERROR 180-322: Statement is not valid or it is used out of proper order". I've tried changing the order and a bunch of different things, none of them worked.
What am I missing?
Here's the code:
propvar = var/sum(var); /* proportion of variance explained by each PC */
x = do(1, 15, 1);
y = cusum(propvar);
title "Cumulative Proportion of Variance Explained by each PC";
call Series(x,y) option="markers"
grid= {x y}
label={"Principal Component" "Cumulative Proportion of Variance Explained"}
xvalues = 1:15
yvalues = do(0,1,0.2);
plot.SetAxisViewRange( YAXIS, 0, 1 );
Thanks in advance!
Please when asking about an error message copy from the log the entire code of the procedure or data step with the error messages and paste that into a code box opened using the forum's {I} menu icon.
The entire procedure or data step is needed because sometimes the actual cause is a missing item such as a semicolon, quote or parentheses from a previous line. Pasting into the code box helps to preserve formatting of the error message. Many of the error messages will indicate where SAS identifies an error with an underscore associated with the message an that helps diagnose things.
Hi there,
Thank you for the heads up (I'm new to the forum too).
So here's the log from the piece of code which has an error:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 proc iml; NOTE: IML Ready 74 use work.pcs; 75 read all var _ALL_ into pcs_matrix; 76 close work.pcs; 77 /* creating a module to run regression inside SAS IML */ 78 start Regress; 78 ! /* begin module */ 79 n = nrow(x); 79 ! /* sample size */ 80 c = j(n, 1, 1); 80 ! /* column vector of 1s */ 81 x = c||x; 81 ! /* concatenating */ 82 xpxi = inv(x`*x); 82 ! /* inverse of X'X */ 83 beta = xpxi * (x`*y); 83 ! /* parameter estimate */ 84 yhat = x*beta; 84 ! /* predicted values */ 85 resid = y-yhat; 85 ! /* residuals */ 86 87 sse = ssq(resid); 87 ! /* SSE */ 88 n = nrow(x); 88 ! /* sample size */ 89 dfe = nrow(x)-ncol(x); 89 ! /* error DF */ 90 mse = sse/dfe; 90 ! /* MSE */ 91 cssy = ssq(y-sum(y)/n); 91 ! /* corrected total SS */ 92 rsquare = (cssy-sse)/cssy; 92 ! /* RSQUARE */ 93 results = sse || dfe || mse || rsquare; 94 /*print results[c={"SSE" "DFE" "MSE" "RSquare"} 95 L="Regression Results"];*/ 96 finish Regress; NOTE: Module REGRESS defined. 96 ! /* end module */ 97 r2_vec= j(15, 1, 1); 97 ! *vector to store the R-squared values; 98 y = pcs_matrix[,1]; 99 do i = 2 to 16 by 1; 100 x = pcs_matrix[,2:i]; 101 run Regress; 102 r2_vec[i-1] = rsquare; 103 end; 104 title "R^2 Values for Regression with 1:15 PC's"; 105 print r2_vec; 106 title; 107 108 /* Next compare these two plots: 109 ... cumulative proportion of variance explained, and 110 ... R-squared with this many principal components */ 111 112 113 x = do(1, 15, 1); 114 y = r2_vec; 115 title "R-square vs number of PCs in the model"; 116 call Series(x,y) option="markers" 117 grid= {x y} 118 label={"Principal Component" "R-squared with this many principal components"} 119 xvalues = 1:15 120 yvalues = do(0,1,0.2); NOTE: Module SERIES loaded from the storage SASHELP.IMLMLIB. NOTE: Module ISEMPTY loaded from the storage SASHELP.IMLMLIB. NOTE: The data set WORK._SERIES has 15 observations and 2 variables. 121 plot.SetAxisViewRange( YAXIS, 0, 1 ); _____________________ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 122 /* 1. Use the OPTION= option to display markers 123 2. Use the GRID= option to add a reference grid 124 3. Use the LABEL= option to specify axis labels 125 4. Use the XVALUES= and YVALUES= options to specify tick positions */ 126 127 use work.eigenvalues; 128 read all var _ALL_ into var; 129 close work.eigenvalues; 130 propvar = var/sum(var); 130 ! /* proportion of variance explained by each PC */ 131 x = do(1, 15, 1); 132 y = cusum(propvar); 133 title "Cumulative Proportion of Variance Explained by each PC"; 134 call Series(x,y) option="markers" 135 grid= {x y} 136 label={"Principal Component" "Cumulative Proportion of Variance Explained"} 137 xvalues = 1:15 138 yvalues = do(0,1,0.2); NOTE: The data set WORK._SERIES has 15 observations and 2 variables. 139 plot.SetAxisViewRange( YAXIS, 0, 1 ); _____________________ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 140 141 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 154
I appreciate your patience and comments!
I don't use IML (not licensed) but the error confirms partially what I thought might be happening. You are modifying a "plot" that hasn't been fully defined.
I find this reference for IML studio using that same syntax but note that the portion that comes prior from http://support.sas.com/documentation/cdl/en/imlsstat/66110/HTML/default/viewer.htm#imlsstat_stataxes...
declare DataObject dobj; dobj = DataObject.CreateFromFile("Hurricanes"); declare ScatterPlot plot; plot = ScatterPlot.Create( dobj, "min_pressure", "wind_kts" );
and then the example adds:
plot.SetAxisLabel ( XAXIS, AXISLABEL_VARLABEL ); plot.SetAxisTickUnit( XAXIS, 20 ); plot.SetAxisTickAnchor( XAXIS, 900 ); plot.SetAxisMinorTicks( XAXIS, 1 );
Which all modify the object "plot" as defined in the DECLARE statement.
What I am not sure of is whether you are using IML Studio, which may have additional methods than available in basic IML code or what the adjustments would be in the basic IML code for Call series.
This might be one of the times when you send the data out to another procedure like SGPLOT to have more control over desired appearance.
Use the DATA with Proc SGPLOT. The graphics elements in Proc IML are not as "full featured" due to the nature of the IML procedure.
SAS Studio is not the same as IML Studio. IML Studio provides an additional interface into IML. SAS provides a number of different "Studios" for different applications such as Forecasting.
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.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.