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

Hey all,

 

I tried to format the values of the xaxis from numeric to scientific notation, because I thought that might be an explanation why the tick intervals of 5000 don't work. It would be sufficient to have just minor ticks without notation.
Every format I could find here ( https://documentation.sas.com/?docsetId=grstatproc&docsetVersion=9.4&docsetTarget=n0kdscfhkob956n196...) is without explanation and not working also.

Gross E8 worked previously with proc boxplot, but not with sgplot.

 

Where can I find explanation for the available formats and how can I change my xaxis values properly?

 

Bild 04.09.19 um 10.54.jpg

 

 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         proc sgplot data=income;
 74         histogram dollar;
 75         yaxis values=(0 to 62 by 5) grid;
 76         xaxis values=(0 to 105E3 by 5E3) valuesformat=best;
 77         run;
 
 ERROR 772-580: Syntaxfehler: Konstanter oder dynamischer Wert erwartet.
 WARNING: Object will not be saved.
 NOTE:  Verwendet wurde: PROZEDUR SGPLOT - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.02 seconds
       
 NOTE: The SAS System stopped processing this step because of errors.
 78         
 79         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

 Thank you so much!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Use e. format and option minor, and specify the values for major ticks only :

 

data test;
call streaminit(67678568);
do i = 1 to 200;
    dollar = 1e5 * rand("Beta", 4, 4);
    output;
    end;
run;

proc sgplot data=test;
histogram dollar;
xaxis values=(0 to 105E3 by 1E4) minor minorcount=1 valuesformat=e8. ;
run;

SGPlot11.png

PG

View solution in original post

13 REPLIES 13
Reeza
Super User
Try just applying a format to your dollar variable?

format variable best12.;

You always need a period after formats, it's missing in your code.
Lacona
Quartz | Level 8
proc sgplot data=income;
histogram dollar;
format dollar best12.;
yaxis values=(0 to 62 by 5) grid;
xaxis values=(0 to 105E3 by 5E3);
run;

I ran that without any changes in the xaxis.

Furthermore: my goal is it to have minor ticks on the xaxis, how do I do that?

Reeza
Super User
BEST isn't the format you want though, don't you want Exponential? You aren't using an exponential format. I just put BEST because it's what's you used.
Lacona
Quartz | Level 8

Sorry, I'm completely new to SAS, never did anything like this before.
I can't find a list whatsoever for SAS formats and what they do and how they look like, so I don't know how they are supposed to be.
I tried this now:

proc sgplot data=income;
histogram dollar;
format dollar 12.;
yaxis values=(0 to 62 by 5) grid;
xaxis values=(0 to 105E3 by 5E3);
run;

but no changes on the xaxis.

Reeza
Super User

You should probably bookmark the documentation page then:

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=pgmsashome&docsetTarget=h...

 

From there you can usually find everything you need, in this case click on formats and then search for scientific notation. Note the document type field as well - you likely want "Document: SAS Formats and Informats: Reference" not DS2. 

 

 

Ew.
Writes numeric values in scientific notation.
Product: Base SAS
Document: SAS DS2 Language Reference

 

proc sgplot data=income;
histogram dollar;
format dollar 12.;
yaxis values=(0 to 62 by 5) grid;
xaxis values=(0 to 105E3 by 5E3);
format dollar e8.;
run;

 

Lacona
Quartz | Level 8

I tried to run it with ew. but nothing changed.

Reeza
Super User
ew is incorrect you need to replace that w by the width which is a number.
PaigeMiller
Diamond | Level 26

@Lacona wrote:

Sorry, I'm completely new to SAS, never did anything like this before.
I can't find a list whatsoever for SAS formats and what they do and how they look like, so I don't know how they are supposed to be.
I tried this now:

proc sgplot data=income;
histogram dollar;
format dollar 12.;
yaxis values=(0 to 62 by 5) grid;
xaxis values=(0 to 105E3 by 5E3);
run;

but no changes on the xaxis.


I don't think the format command does anything in PROC SGPLOT, although it does work in most other procedures. In PROC SGPLOT you need the VALUESFORMAT= option of the XAXIS and/or YAXIS statement.

 

List of every known format in SAS 9.4:

https://documentation.sas.com/?cdcId=pgmmvacdc&cdcVersion=9.4&docsetId=allprodslang&docsetTarget=syn...

--
Paige Miller
Reeza
Super User
SGPLOT will honour the format applied to a variable within the axis labels. It's often used when you need to control the order of bars for example so you code them as numeric and use a format to have the values displayed appropriately.

ValuesFormat can be used as well - but I think it's usually used to override the format on the variable or when you have dates you want displayed differently. Or at least those are the use cases I've seen so far.

Just tested on SAS 9.4M5

PaigeMiller
Diamond | Level 26

@Lacona wrote:

Hey all,

 

I tried to format the values of the xaxis from numeric to scientific notation, because I thought that might be an explanation why the tick intervals of 5000 don't work. It would be sufficient to have just minor ticks without notation.
Every format I could find here ( https://documentation.sas.com/?docsetId=grstatproc&docsetVersion=9.4&docsetTarget=n0kdscfhkob956n196...) is without explanation and not working also.

Gross E8 worked previously with proc boxplot, but not with sgplot.

 

Where can I find explanation for the available formats and how can I change my xaxis values properly?

 

Bild 04.09.19 um 10.54.jpg

 

 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         proc sgplot data=income;
 74         histogram dollar;
 75         yaxis values=(0 to 62 by 5) grid;
 76         xaxis values=(0 to 105E3 by 5E3) valuesformat=best;
 77         run;
 
 ERROR 772-580: Syntaxfehler: Konstanter oder dynamischer Wert erwartet.
 WARNING: Object will not be saved.
 NOTE:  Verwendet wurde: PROZEDUR SGPLOT - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.02 seconds
       
 NOTE: The SAS System stopped processing this step because of errors.
 78         
 79         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

 Thank you so much!


Note the dot after the word best

 

xaxis values=(0 to 105E3 by 5E3) valuesformat=best.;

Although as others have said, maybe you don't want the BEST. format in this case.

--
Paige Miller
PGStats
Opal | Level 21

Use e. format and option minor, and specify the values for major ticks only :

 

data test;
call streaminit(67678568);
do i = 1 to 200;
    dollar = 1e5 * rand("Beta", 4, 4);
    output;
    end;
run;

proc sgplot data=test;
histogram dollar;
xaxis values=(0 to 105E3 by 1E4) minor minorcount=1 valuesformat=e8. ;
run;

SGPlot11.png

PG
Panagiotis
SAS Employee

To confirm, you are trying to add the scientific notation format to the xaxis in your histogram?

 

Try this. I am using the SASHELP.CARS table that you probably have available:

 

/*Copy SASHELP.CARS, copy MSRP to Price. Price has no format*/
data cars;
	set sashelp.cars;
	keep Price;
	Price=MSRP;
run;

/*Default histogram. No format or new xaxis values*/
proc sgplot data=cars;
	histogram price;
run;

/*Add a format and new xaxis values range*/
proc sgplot data=cars;
	histogram price;
	xaxis values=(0 to 200000 by 25000);
	format price e8.;
run;

Graphs.jpg

Lacona
Quartz | Level 8

Yesss!!! It worked! Thank you all!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 13 replies
  • 9476 views
  • 5 likes
  • 5 in conversation