BookmarkSubscribeRSS Feed
capam
Pyrite | Level 9

Hi,

 

I need to plot a vbar like plot with a subset that is highlighted. I tried the following and got an error message.

 

proc sgplot data=has;
	yaxis label= "...";
	vbar VEHICLE_NO;
	vbar VEHICLE_NO_subset;
run;

The error message follows:


ERROR: The same category variable must be used for summarized plots.

4 REPLIES 4
capam
Pyrite | Level 9

The subset was generated as:

 

data has;
	set has;
	by vehicle_no;

	if FAULT_CODE = '20-2018' and VEHICLE_NO in ("3725" "3727" "3728" "3729" 
		"3730" "3734" "3737" "3739" "3740" "3741" "3742" "3745" ) then
		do;
			vehicle_no_subset=vehicle_no;
		end;
run;
BrunoMueller
SAS Super FREQ

You can use the VBARPARM statement with aggregated data using two different category variables or you make use of an additional

grouping variable and use the VBAR statement

 

See code sample below.

 

data cars2;
  set sashelp.cars;
  length group $ 8;
  if type = "SUV" then do;
    group = "SUV";
  end;
  else do;
    group="other";
  end;
run;

proc sgplot data=cars2 noautolegend;
  vbar type / response=invoice stat=mean group=group ;
run;

data vehicle;
  length  
    vehicle_no vehicle_no_subset $ 8
  ;
  do vehicle_no = "3725", "3727", "3728", "3729", "4725", "4727", "4728", "4729";
    response + 1;
    call missing(vehicle_no_subset);
    if vehicle_no in ("3725", "3727", "3728", "3729") then do;
      vehicle_no_subset = vehicle_no;
    end;
    output;
  end;
run;

proc sgplot data=work.vehicle;
  vbarparm category=vehicle_no response=response;
  vbarparm category=vehicle_no_subset response=response;
run;

capam
Pyrite | Level 9
Thanks Bruno.

I'm not clear on initializing response.. Also, the do in 'do vehicle_no in ...' is not in purple. There may be a syntax error.
BrunoMueller
SAS Super FREQ

Just try the code I provided, to see if the graphs looks the way you intend. Since you did not provide any test data, I had to create some data myself.

 

You then need to adapt your code accordingly either using the technique with the "group" variable or have a second category variable and use the VBARPARM statement. this data needs to be aggregated, as VBARPARM just plots the information, but does not do any aggregation.

 

 

sas-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

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
  • 4 replies
  • 1955 views
  • 1 like
  • 2 in conversation