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

Hello all,

 

I expect to create a figure 

 

for the following data,

data have;
INFILE CARDS DSD DLM=',';
input
CTRY :$10.
INDUSTRY :$29.
R&D :8
PATENTS :8
;
cards;
AT,Manufacure,4316550,2033058
AU,Manufacure,2701929,961452
BE,Manufacure,1935804,564041
AT,Service,2069617,483619
AU,Service,1058213,235353
BE,Service,1024675,60304
AT,Oil,1725920,242679
AU,Oil,2178870,543554
BE,Oil,1024675,60304
;
run;

I expect to create three X Y scatter for each INDUSTRY

 

I would like to put the value of "R&D" at Y-axis and value of "Patent" at X-axis and the value of "INDUSTRY" as the title of each scatter. SO the value of each country is expected to be displayed as a point on each scatter chart.

 

Could you please give me some suggestion about this?

thanks in advance.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RichardDeVen
Barite | Level 11

For three plots in one image, you will want to use Proc SGPANEL. 

 

  • PANELBY statement lets you specify the variables (1 or 2) that control the data subset going each panels.
  • SCATTER statement lets you specify the X and Y variables, and the data point labeling variable.

 

Proper data is important, the sample in your question does not input properly.  The sample code below fixes the input:

 

data have;
attrib 
  country_code length=$2
  industry     length=$20 label = "INDUSTRY"
  rnd          format=dollar12. label = 'R & D'
  patents      format=dollar12. label = 'Patent'
;

INFILE CARDS DSD DLM=','; input
country_code industry rnd patents;
datalines;
AT,Manufacture,4316550,2033058
AU,Manufacture,2701929,961452
BE,Manufacture,1935804,564041
AT,Service,2069617,483619
AU,Service,1058213,235353
BE,Service,1024675,60304
AT,Oil,1725920,242679
AU,Oil,2178870,543554
BE,Oil,1024675,60304
;

proc sgpanel data=have;
  panelby industry / columns=1;
  scatter x=patents y=rnd / datalabel=country_code;  
run;

image.png

View solution in original post

2 REPLIES 2
Reeza
Super User

Have you tried the first example in SGPLOT documentation?
https://documentation.sas.com/?docsetId=grstatproc&docsetTarget=n06fb9ichgg6akn18060gbtvw9pw.htm&doc...

To split by industry instead of group it, use a BY statement and don’t use the GROUP option. 


@Alexxxxxxx wrote:

Hello all,

 

I expect to create a figure 

 

for the following data,

data have;
INFILE CARDS DSD DLM=',';
input
CTRY :$10.
INDUSTRY :$29.
R&D :8
PATENTS :8
;
cards;
AT,Manufacure,4316550,2033058
AU,Manufacure,2701929,961452
BE,Manufacure,1935804,564041
AT,Service,2069617,483619
AU,Service,1058213,235353
BE,Service,1024675,60304
AT,Oil,1725920,242679
AU,Oil,2178870,543554
BE,Oil,1024675,60304
;
run;

I expect to create three X Y scatter for each INDUSTRY

 

I would like to put the value of "R&D" at Y-axis and value of "Patent" at X-axis and the value of "INDUSTRY" as the title of each scatter. SO the value of each country is expected to be displayed as a point on each scatter chart.

 

Could you please give me some suggestion about this?

thanks in advance.

 

 


 

RichardDeVen
Barite | Level 11

For three plots in one image, you will want to use Proc SGPANEL. 

 

  • PANELBY statement lets you specify the variables (1 or 2) that control the data subset going each panels.
  • SCATTER statement lets you specify the X and Y variables, and the data point labeling variable.

 

Proper data is important, the sample in your question does not input properly.  The sample code below fixes the input:

 

data have;
attrib 
  country_code length=$2
  industry     length=$20 label = "INDUSTRY"
  rnd          format=dollar12. label = 'R & D'
  patents      format=dollar12. label = 'Patent'
;

INFILE CARDS DSD DLM=','; input
country_code industry rnd patents;
datalines;
AT,Manufacture,4316550,2033058
AU,Manufacture,2701929,961452
BE,Manufacture,1935804,564041
AT,Service,2069617,483619
AU,Service,1058213,235353
BE,Service,1024675,60304
AT,Oil,1725920,242679
AU,Oil,2178870,543554
BE,Oil,1024675,60304
;

proc sgpanel data=have;
  panelby industry / columns=1;
  scatter x=patents y=rnd / datalabel=country_code;  
run;

image.png

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 721 views
  • 1 like
  • 3 in conversation