BookmarkSubscribeRSS Feed
FrankPoppe
Quartz | Level 8

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 ;
9 REPLIES 9
AncaTilea
Pyrite | Level 9

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

FrankPoppe
Quartz | Level 8

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

Jay54
Meteorite | Level 14

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

FrankPoppe
Quartz | Level 8

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.

Jay54
Meteorite | Level 14

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

Jan_TSNL
SAS Employee

Dear Frank & Sanjay,

We just made a Defect out of this.

Thanks for your input, making SAS better!

Smiley Happy

AndyK_
Calcite | Level 5

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.

Jay54
Meteorite | Level 14

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 ;

AndyK_
Calcite | Level 5
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.

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
  • 9 replies
  • 2871 views
  • 3 likes
  • 5 in conversation