Data visualization with SAS programming

SGPLOT VBAR and a user defined format on the category variable

Reply
Contributor
Posts: 41

SGPLOT VBAR and a user defined format on the category variable

Hi,

I started to use SGPLOT (it was on my list for sometime, but now I doing work for a site with EG connected to a server that does not have SAS/Graph).

I had a simple VBAR very quickly, but am surprised that user defined formats do not seem to work when used on the variable that defines the bars.

As an example I have the following code (changed to work with a SASHELP table). I added the GPLOT and FREQ procs just to show the effect of the user defined format.

When I use the NLDATEMD format it runs as expected, grouping data per month-day combination.

When I use the DAGNUM format SGPLOT shows one bar labeled %0d, and prints a warning "The data for a BARCHARTPARM statement are not appropriate. The BARCHARTPARM statement expects summarized data. The bar chart might not be drawn correctly." But the NLDATEMD format also leads to aggregation, and this happens without problems. And my original code did have only one observation per bar (it contained data for a single month, that's why I wanted only the number of the day displayed).

We have SAS 9.3 on the server.

Or am I missing something in the documentation; or doing something silly?

proc format ; 
picture dagnum  low-high='%0d' ( datatype=date );
run ;
data ;
do x = '1jun2013'd to '30jun2013'd by 5 ;
put x= dagnum2. ;
end ;
run ;


/*%let format = nldatemd. ;*/
%let format = dagnum. ;

proc sgplot data=sashelp.stocks ( where= (stock="IBM") ) ;
vbar date / response=open ;
format date &format ;
run ;

proc gchart data=sashelp.stocks ( where= (stock="IBM") ) ;
vbar date / discrete sumvar=open ;
format date &format ;
run ;

proc freq  data=sashelp.stocks ( where= (stock="IBM") ) ;
tables date ;
format date &format ;
run ;
Super Contributor
Posts: 543

Re: SGPLOT VBAR and a user defined format on the category variable

Posted in reply to FrankPoppe

Hi,

the first thing that comes to mind is that you are missing the letter 't' in the &format in this statement:

proc gchart data=sashelp.stocks ( where= (stock="IBM") ) ;

vbar date / discrete sumvar=open ;

format date &forma;

run ;

Try and see what happens now?

Smiley Happy

Contributor
Posts: 41

Re: SGPLOT VBAR and a user defined format on the category variable

Posted in reply to AncaTilea

Sorry, that was a typo introduced while formatting this message. I'll edit the message.

SAS Super FREQ
Posts: 1,171

Re: SGPLOT VBAR and a user defined format on the category variable

Posted in reply to FrankPoppe

There may be a bug with the java formatter for this particular format.  Try this code.  It formats the data on server, and then sends it to SGPLOT.  The warning message is an internal issue that may be a bit confusing.  We'll look into it.

proc format ;
picture dagnum  low-high='%0d' ( datatype=date );
run ;

data ;
do x = '1jun2013'd to '30jun2013'd by 5 ;
put x= dagnum2. ;
end ;
run ;

data formatted;
  set sashelp.stocks ( where= (stock="IBM") );
  NewDate=put(date, dagnum2.);
run;


proc sgplot data=formatted ;
vbar newdate / response=open

run ;

Dagnum1.png

Contributor
Posts: 41

Re: SGPLOT VBAR and a user defined format on the category variable

Posted in reply to Sanjay_SAS

OK, thanks,

First massaging the data is of course an option. I tried to avoid that.

I won't even need the format then, I can just use the DAY function.

SAS Super FREQ
Posts: 1,171

Re: SGPLOT VBAR and a user defined format on the category variable

Posted in reply to FrankPoppe

It is likely a bug.  Feel free to report it to Tech Support.  We'll look into it.

SAS Employee
Posts: 1

Re: SGPLOT VBAR and a user defined format on the category variable

Posted in reply to FrankPoppe

Dear Frank & Sanjay,

We just made a Defect out of this.

Thanks for your input, making SAS better!

Smiley Happy

Occasional Contributor
Posts: 10

Re: SGPLOT VBAR and a user defined format on the category variable

I'm still seeing this bug in 9.4. As Sanjay mentioned, a workaround is to write the variable with the user-defined format into a new variable without a user-defined format (using PUT).

 

In my experience this error is thrown inconsistently, requiring previously error-free code to be patched.

SAS Super FREQ
Posts: 1,171

Re: SGPLOT VBAR and a user defined format on the category variable

User Defined Formats are supported in general for SGPLOT, but there is a known lack of support for some picture format features for all ODS Graphics procedures.  As mentioned earlier, a workaround would be to create another variable day=put(date, dagnum.); and then plot that.

 

data stocks;
  set sashelp.stocks ( where= (stock="IBM") );
  day=put(date, dagnum.);
run;

 

proc sgplot data=stocks ( where= (stock="IBM") ) ;
  vbar day / response=open ;
run ;

Occasional Contributor
Posts: 10

Re: SGPLOT VBAR and a user defined format on the category variable

Posted in reply to Sanjay_SAS
Thanks Sanjay, that's good to know. I will keep an eye out on other ODS graphics procedures. In my particular case it was a user-defined numeric format causing the issue, not a picture format.
Ask a Question
Discussion stats
  • 9 replies
  • 1083 views
  • 3 likes
  • 5 in conversation