BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sm4
Quartz | Level 8 sm4
Quartz | Level 8

Hello,

 

I have a dataset like this:

 

 01NOV2017, -0.3
01OCT2017, -0.5
01SEP2017, -0.2
01AUG2017, 0.4
01JUL2017, 0.5
01JUN2017, 0.6
01MAY2017, 0.5
01APR2017, 0.3
01MAR2017, 0.6
01FEB2017, 0.2
01JAN2017, 0.5
01DEC2016, 0.4
01NOV2016, 0.2
01OCT2016, 0.5
01SEP2016, 0.6
01AUG2016, 0.5
01JUL2016, 0.4
01JUN2016, 0.6

When I graph it in proc sgplot (output to rtf), I want every value to appear on the x-axis (each and every month). I tried the x-axis option "interval= month", but that had no effect. So I started using the x-axis option "type= discrete", and that works.

 

But I also want the date values to be formatted in the graphing step (so that I don't have to include an additional data step - since I may have to do a number graphs): 01NOV2016 --> Nov-16, for example. The x-axis option "valuesformat = MONYY." mostly accomplishes this, but it is not compatible with type= discrete. I tried "tickvalueformat= MONYY" but that had no effect at all.

 

 

Any way to get these both to work?

 

I'm really new to graphing in SAS, so I'm probably missing some really basic knowledge. Would appreciate if someone could correct me!

 

Thanks!

1 ACCEPTED SOLUTION
6 REPLIES 6
Reeza
Super User

Code?

 


@sm4 wrote:

Hello,

 

I have a dataset like this:

 

 01NOV2017, -0.3
01OCT2017, -0.5
01SEP2017, -0.2
01AUG2017, 0.4
01JUL2017, 0.5
01JUN2017, 0.6
01MAY2017, 0.5
01APR2017, 0.3
01MAR2017, 0.6
01FEB2017, 0.2
01JAN2017, 0.5
01DEC2016, 0.4
01NOV2016, 0.2
01OCT2016, 0.5
01SEP2016, 0.6
01AUG2016, 0.5
01JUL2016, 0.4
01JUN2016, 0.6

When I graph it in proc sgplot (output to rtf), I want every value to appear on the x-axis (each and every month). I tried the x-axis option "interval= month", but that had no effect. So I started using the x-axis option "type= discrete", and that works.

 

But I also want the date values to be formatted in the graphing step (so that I don't have to include an additional data step - since I may have to do a number graphs): 01NOV2016 --> Nov-16, for example. The x-axis option "valuesformat = MONYY." mostly accomplishes this, but it is not compatible with type= discrete. I tried "tickvalueformat= MONYY" but that had no effect at all.

 

 

Any way to get these both to work?

 

I'm really new to graphing in SAS, so I'm probably missing some really basic knowledge. Would appreciate if someone could correct me!

 

Thanks!


 

sm4
Quartz | Level 8 sm4
Quartz | Level 8

 

	proc sgplot data= test noborder nowall;
		series x= month y= SA / name= "SA" legendlabel= 'test' markers lineattrs= (color= darkblue thickness = 2) markerattrs= (symbol= diamondfilled color= darkblue);
		series x= month y= UA / name= "UA" legendlabel= 'test' lineattrs= (color= red thickness = 2);
		title1 font= albany height= 11pt bold justify= right 'test';
		title2 font=albany height= 10pt 'test';
		title3 ' ';
		xaxis display=(nolabel) type= discrete tickvalueformat= MONYY. /*valuesformat= MONYY.*/ interval= month labelattrs= (family= albany size= 10px weight=bold);
		yaxis label= 'test' labelattrs= (family= albany weight= bold) valueattrs= (family= albany weight= bold) values= (-0.025 to 0.025 by 0.005) valuesformat= PERCENTN10.1;
		band x= month upper= 0 lower= -0.03 / fillattrs= (color= antiquewhite) transparency= 0.5; 
		keylegend "SA" "UA"/ location= inside position= top valueattrs= (family= albany weight=bold) noborder;
	run;


I tried putting my dataset through datalines but was having formatting issues so finally gave up.

 

Thank you!

 

Reeza
Super User

What about the following options together:

 

type=date

interval=month

valuesformat=monyy7.

values = (start to end by interval)

 

Demo here, but read your log carefully. If you have too many tick values it won't print them and you have to adjust them to fit etc. but this gets one per month and formatted as stated. 

 

SAS 9.4TS1M5

 

proc sgplot data=sashelp.stocks;
where stock='IBM' and year(date) = 2000 ;
series x=date y=open / markers;
xaxis interval=month valuesformat=monyy7. 
    type=time 
        values=('01Jan2000'd to '31Dec2000'd by 1);
run;

@sm4 wrote:

 

	proc sgplot data= test noborder nowall;
		series x= month y= SA / name= "SA" legendlabel= 'test' markers lineattrs= (color= darkblue thickness = 2) markerattrs= (symbol= diamondfilled color= darkblue);
		series x= month y= UA / name= "UA" legendlabel= 'test' lineattrs= (color= red thickness = 2);
		title1 font= albany height= 11pt bold justify= right 'test';
		title2 font=albany height= 10pt 'test';
		title3 ' ';
		xaxis display=(nolabel) type= discrete tickvalueformat= MONYY. /*valuesformat= MONYY.*/ interval= month labelattrs= (family= albany size= 10px weight=bold);
		yaxis label= 'test' labelattrs= (family= albany weight= bold) valueattrs= (family= albany weight= bold) values= (-0.025 to 0.025 by 0.005) valuesformat= PERCENTN10.1;
		band x= month upper= 0 lower= -0.03 / fillattrs= (color= antiquewhite) transparency= 0.5; 
		keylegend "SA" "UA"/ location= inside position= top valueattrs= (family= albany weight=bold) noborder;
	run;


I tried putting my dataset through datalines but was having formatting issues so finally gave up.

 

Thank you!

 


 

sm4
Quartz | Level 8 sm4
Quartz | Level 8

Thank you!!
Tried that out, and it looks like it's getting closer to working because now only a couple of months are left off. I figured this has to do with the fact that it persistently will not rotate the tick values and by default 'thins' them for time-type axes, so I tried adding a 'FITPOLICY= ROTATE' in the xaxis statement. It gives this log note:

 

NOTE: TICKVALUEFITPOLICY=Rotate is ignored when SPLITTICKVALUE=TRUE. The default THIN policy is used.
NOTE: Some of the tick values have been thinned.

 

When I googled the SPLITTICKVALUE option to change it to FALSE, it only brought up GTL/layout overlay references. So I tried adding this to my original proc template:

 

	define statgraph series;
		begingraph;
			layout overlay/
				xaxisopts=(type= time timeopts=(tickvalueformat= monyy7. splittickvalue= false));
			endlayout;
		endgraph;
	end;

The template was defined successfully, but I could not find how to reference it in the proc sgplot code. The 'template=' did not turn blue in EG either in the first statement or in the body of proc sgplot:

 

	proc sgplot data= test noborder nowall template= series;

 

It looks like all I need to do to get this to work is to switch SPLITTICKVALUE to FALSE. Any idea on how to do this?

 

Thanks a million for your help! Because of you and others on this site, I'm able to do things in SAS that I knew zero about just a couple of days ago.

sm4
Quartz | Level 8 sm4
Quartz | Level 8

Thanks!! This worked perfectly - with one main modification, which I'll put here for others:

 

When I simply tried adding 'notimesplit' to the xaxis statement, I got a crazy result, where the x-axis was covered in what looked like inkblots. Then I decided to remove the 'values=' statement suggested by Reeza, b/c I figured that was the one most likely to be causing the problem. Then everything worked perfectly. Here is the solution code:

 

	proc sgplot data= test noborder nowall;
		series x= month y= SA / name= "SA" legendlabel= 'test' markers lineattrs= (color= darkblue thickness = 2) markerattrs= (symbol= diamondfilled color= darkblue);
		series x= month y= UA / name= "UA" legendlabel= 'test' lineattrs= (color= red thickness = 2);
		title1 font= albany height= 11pt bold justify= right 'test';
		title2 font=albany height= 10pt 'test';
		title3 ' ';
		xaxis display=(nolabel) type= time notimesplit fitpolicy= rotate valuesformat= MONYY5. interval= month labelattrs= (family= albany size= 10px weight=bold);
		yaxis label= 'test' labelattrs= (family= albany weight= bold) valueattrs= (family= albany weight= bold) values= (-0.025 to 0.025 by 0.005) valuesformat= PERCENTN10.1;
		band x= month upper= 0 lower= -0.03 / fillattrs= (color= antiquewhite) transparency= 0.5; 
		keylegend "SA" "UA"/ location= inside position= top valueattrs= (family= albany weight=bold) noborder;
	run;

the only catch is, I was using this for batch mode SAS via Unix. When I tried to use the same for another set of data in Base SAS (9.4), it doesn't really work (the x-axis options, I mean). The tick values don't line up with the data points, though they were lining up before. Anyway - that's a problem for another time.

Thank you!!!

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 4945 views
  • 2 likes
  • 2 in conversation