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

hi all:

I am stucked in this and can't figure out how to solve the log issue. please advise.

Thank you.


/*Plotting on same graph by ID*/
ods results off;
ods listing close;
ods rtf file = "c:\plot.rtf";		

proc sgplot data=have noautolegend;
   series x=time1 y=y1/break  markers ;
	 series x=time1 y=y2/break markers y2axis ;
	 by id;

  xaxis display=(nolabel)      label = "Time(Day)";
  yaxis grid  values = (5 to 100 by 10)          label="y1";
	y2axis values= (0 to 100 by 10)	               label="y2";
	keylegend "y1 y2" / location=inside position=top; 
run; 

ods rtf close;
ods listing;
ods results on;

purpleclothlady_0-1680629750608.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Thanks for providing the data in a usable form.

 

When I run your code, I do not get the message about the tick values being thinned. Perhaps your or I have different default options set. Tick values are thinned if there are too many to fit on your axis. You can try something like this:

 

ods graphics / height=5in width=7in;

 

and then try different values for height= and width= to see if you can make the message go away.

 

As far as the WARNING

 

WARNING: Y=Y2 is invalid. The option expects that the column not contain all missing values.

 

Some of your BY variable levels have all missing values. This should be obvious if you either look at your data set with your own eyes, or look at the output plots, or run PROC FREQ on Y2 with by id;

--
Paige Miller

View solution in original post

17 REPLIES 17
PaigeMiller
Diamond | Level 26

It's nearly impossible for us to work from partial LOGs, we need to see the ENTIRE log for this PROC SGPLOT. We also need to see a portion of the data set named HAVE, presented as working SAS data step code (and not via any other method).

 

By the way, the WARNING about Y=Y2 is invalid seems rather clear to me. What part is not clear?

--
Paige Miller
purpleclothlady
Pyrite | Level 9

Hi @PaigeMiller :

 

Have data is attached again as have.sas7bdat

log is attached as havelog.docx

 

Thanks so much for helping.

 

here is code 

data have;
set f.have;
run;
proc sort;by id time1;run;

/*Plotting on same graph by ID*/
ods results off;
ods listing close;
ods rtf file = "C:\Users\Temp\plot.rtf";		

proc sgplot data=have noautolegend;
   series x=time1 y=y1/break  markers ;
   series x=time1 y=y2/break markers y2axis ;
   by id;

  xaxis display=(nolabel)      label = "Time(Day)";
  yaxis grid  values = (5 to 100 by 10)          label="y1";
	y2axis values= (0 to 100 by 10)	               label="y2";
	keylegend "y1 y2" / location=inside position=top; 
run; 
ods rtf close;
ods listing;
ods results on;

 

Rick_SAS
SAS Super FREQ

For some reason I cannot open your SAS data set, but here are my thoughts:

1. The WARNING says that PROC SGPLOT thinks that the Y2 variable contains only missing values. This usually happens when the variable was read incorrectly. Try running
proc means data=have min max N NMISS;
var time1 y1 y2;
run;

to see if Y2 has any nonmissing values;

 

2. The NOTE says that the plot is large enough to plot all the tick marks. I don't know if it is the X or Y axis that is complaining, but the output from PROC MEANS should help us decide. This error can also occur if you are reading X from an excel spreadsheet and the TIME1 variable is being read as a character variable rather than as numeric with a time or date format. So make sure the range of TIME1 makes sense.

 

 

purpleclothlady
Pyrite | Level 9

@Rick_SAS :

Thank you for helping.

Here is the proc means output and snippet of "Have" dataset

- Y1, Y2 had some missing values , but NOT all were missing.

- Time1 is numeric variables 

-Data was taken from sas datasets

 

purpleclothlady_0-1680698771253.png

 

Rick_SAS
SAS Super FREQ

You need to add

BY ID;

to your PROC MEANS call.

 

Your output shows that OVERALL, not all of the Y values are missing. However, you have BY ID in the call to PROC SGPLOT, which means that it will try to create a plot for each value of the ID variable. I am confident that some of your ID values have all missing values for a Y variable.

 

For an example, run .this test program:

data Test;
ID = 1;
do time1 = 1 to 10;
   y2 = time1;
   if time1 in (3,4,8) then y2=.;
   output;
end;
ID = 2;
do time1 = 1 to 5;
   y2 = .;
   output;
end;
ID = 3;
do time1 = 1 to 5;
   y2 = 5-time1;
   if time1 in (3,5) then y2=.;
   output;
end;
run;

proc sgplot data=Test;
   series x=time1 y=y2 / break markers;
   by ID;   /* Note all values of Y2 are missing when ID=2 */
run;
PaigeMiller
Diamond | Level 26

Some of us (like me) refuse to download attached files.

 

The log you can post in your message as text. Data should be provided as working SAS data step code (instructions).

--
Paige Miller
ballardw
Super User

Any time you attempt to create more tick marks than will display reasonably, given the options you provide, SAS will thin, i.e. reduce the number of values shown based on the current value of the FITPOLICY setting  to create something legible. The default for an axis not set with the Type= option is to THIN. You get one message for each graph, value of your BY variable.

 

An example of looking at some options affecting an axis and how many tick marks and the text displayed. The title comments about how well text displays is based on my ods graphics width and height settings so you may not get exactly the same result but hopefully see changes based on changing the TYPE= option which changes the default Fitpolicy from Thin to StaggerRotate, and the affect of the number of requested ticks plus changing the ValuesRotate from slant to vertical.

 

Text attributes may also play a part in causing thinning if the text is tall enough to encroach on tick text above/below the values.

So look up FITPOLICY options on the yaxis and y2axis, Type=, and other text display options and play with them.

data junk;
   do x= 1 to 1000;
     y= sin(x/200);
     output;
   end;
run;

proc sgplot data=junk;
  title "Request too many ticks, x axis thinned default fitpolicy=thin";
  series x=x y=y;
  xaxis values= (0 to 1000 by 1);
run; title;
proc sgplot data=junk;
  title "Request too many ticks, x axis discrete likely unreadable";
  series x=x y=y;
  xaxis values= (0 to 1000 by 1) type=discrete;
run; title;
proc sgplot data=junk;
  title "Request too many ticks fewer, x axis discrete, not quite readable";
  series x=x y=y;
  xaxis values= (0 to 1000 by 10) type=discrete;
run; title;

proc sgplot data=junk;
  title "Request many ticks much fewer, x axis discrete, almost readable";
  series x=x y=y;
  xaxis values= (0 to 1000 by 20) type=discrete;
run; title;
proc sgplot data=junk;
  title "Request many ticks much fewer, x axis discrete, barely readable";
  series x=x y=y;
  xaxis values= (0 to 1000 by 20) type=discrete valuesrotate=vertical;
run; title;
proc sgplot data=junk;
  title "Request too many ticks much fewer, x axis discrete, probably readable";
  series x=x y=y;
  xaxis values= (0 to 1000 by 50) type=discrete;
run; title;

proc sgplot data=junk;
  title "Request many fewer ticks, x axis not thinned";
  series x=x y=y;
  xaxis values= (0 to 1000 by 100);
run; title;
purpleclothlady
Pyrite | Level 9

Hi Geeks: 

I spent some time to use the @PaigeMiller to get

"https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" 

1. the sasdata , now it is available. 

2. proc means does show Y2 for 

PaigeMiller
Diamond | Level 26

Thanks for providing the data in a usable form.

 

When I run your code, I do not get the message about the tick values being thinned. Perhaps your or I have different default options set. Tick values are thinned if there are too many to fit on your axis. You can try something like this:

 

ods graphics / height=5in width=7in;

 

and then try different values for height= and width= to see if you can make the message go away.

 

As far as the WARNING

 

WARNING: Y=Y2 is invalid. The option expects that the column not contain all missing values.

 

Some of your BY variable levels have all missing values. This should be obvious if you either look at your data set with your own eyes, or look at the output plots, or run PROC FREQ on Y2 with by id;

--
Paige Miller
Rick_SAS
SAS Super FREQ

To get a dashed line when the data are missing, use the trick explained in "A trick to plot a time series that has missing values,"

 which shows how to overlay two lines:

- a dashed line WITHOUT using the BREAK option

- a solid line that uses the BREAK option

 

To get an X axis that adjusts to the range of the data, add VALUESHINT to the XAXIS statement, which tells the plot to use the VALUES= option as a "hint," not as a mandate.

purpleclothlady
Pyrite | Level 9

hi all @PaigeMiller @Rick_SAS @ballardw :

I updated the code and tested again, it perfectly worked.

EXCEPT 

1. log issue- how to work around the log issue :"WARNING: Y=Y2 is invalid. The option expects that the column
not contain all missing values."

 

2. the Legend is not displaying. 
3. since different ID had different  X Axis, how may I lable the minor ticker ? 

thanks again. this is a really helpful place to solve questions. 

Purple

 

purpleclothlady_0-1680724248360.png



/*********************************************************************
                         PLOTTING -- 
1. Need to  show x scale by ID, do has to use dynamic Time1
2. Need to use SOLID LINES to connect data, but if there is missing Y, then connect with DASHED LINE
**********************************************************************/
/*Plotting on same graph by ID*/

ods results off;
ods listing close;

ods rtf file = "C:\temp\plothave.rtf";		

ods graphics / height=5in width=8in;

proc sgplot data=have noautolegend;
   series x=time1 y=y1 /lineattrs=GraphData1(pattern=dash);       /*creating a dashed line of Y is missing*/
   series x=time1 y=y1/break  markers  lineattrs=GraphData1(pattern=solid thickness=2);

	 series x=time1 y=y2/break markers y2axis ;
	 by id;

  xaxis display=(nolabel)  VALUESHINT    	     label = "Time(Day)";
  yaxis grid  values = (5 to 100 by 10)          label="y1";
	y2axis values=       (0 to 100 by 10)	     label="y2";

	keylegend "y1 y2" / location=inside position=top; 	 /*where does this legend go? */
run; 


ods rtf close;
ods listing;
ods results on;

 

PaigeMiller
Diamond | Level 26

@purpleclothlady wrote:

hi all @PaigeMiller @Rick_SAS @ballardw :

I updated the code and tested again, it perfectly worked.

EXCEPT 

1. log issue- how to work around the log issue :"WARNING: Y=Y2 is invalid. The option expects that the column
not contain all missing values."


I explained #1 earlier. There is no workaround, since some of your IDs have all missing Y2.

 

--
Paige Miller
purpleclothlady
Pyrite | Level 9
Yes. I realized that. I will keep as this unless the data is updated and got some records. thank you again.
Rick_SAS
SAS Super FREQ

Fort the legend, put each name in a separate string:

 

keylegend "y1" "y2" / location=inside position=top; 

For adding minor ticks, add the MINORCOUNT= and MINOR options to the XAXIS statement:

 xaxis minor minorcount=1 display=(nolabel) VALUESHINT label = "Time(Day)";

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 17 replies
  • 4831 views
  • 4 likes
  • 4 in conversation