BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Child79
Fluorite | Level 6

Hello,

Here is my dataset. I have two categorical variables (type_college and name) and a numeric variable (COL1).

I don't know how to plot on the same graph the evolution curves of COL1 according to name for each type_college.

 

 

data students;
  infile datalines dlm=',' dsd;
  informat type_college $15.  name $15. ; 
input  type_college   name $  COL1 ;
datalines;
College private,delai_dec20,1.5
College private,delai_juin21,3.6
College private,delai_dec21,4.4
College private,delai_sep22,47.6
College public,delai_dec20,5.3
College public,delai_juin21,6
College public,delai_dec21,14.4
College public,delai_sep22,14.4
University,delai_dec20,11.1
University,delai_juin21,14.3
University,delai_dec21,14
University,delai_sep22,17.1
,delai_dec20,5.6
,delai_juin21,7.1
,delai_dec21,12
,delai_sep22,18.1
;

here is exactly what I want for result.

Capture d’écran 2022-10-12 000900.png

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Two different methods illustrated below:

 

data students_mod;
set students;
if missing(type_college) then type_college = 'Total';
*get date value for sorting correctly if more dates included;
*may read correctly without compress if your locale is set for your language/location;
Date = input(compress(scan(name, -1, "_"), 'i'), monyy5.);
format date monyy5.;
run;


proc sgplot data=students_mod;
series y=col1 x=date / group = type_college markers datalabel=col1;
format date monyy5.;
keylegend /position=right;
run;

proc sgplot data=students_mod;
series y=col1 x=name / group=type_college datalabel=col1 ;
keylegend /position=right;
run;

@Child79 wrote:

Hello,

Here is my dataset. I have two categorical variables (type_college and name) and a numeric variable (COL1).

I don't know how to plot on the same graph the evolution curves of COL1 according to name for each type_college.

 

 

data students;
  infile datalines dlm=',' dsd;
  informat type_college $15.  name $15. ; 
input  type_college   name $  COL1 ;
datalines;
College private,delai_dec20,1.5
College private,delai_juin21,3.6
College private,delai_dec21,4.4
College private,delai_sep22,47.6
College public,delai_dec20,5.3
College public,delai_juin21,6
College public,delai_dec21,14.4
College public,delai_sep22,14.4
University,delai_dec20,11.1
University,delai_juin21,14.3
University,delai_dec21,14
University,delai_sep22,17.1
,delai_dec20,5.6
,delai_juin21,7.1
,delai_dec21,12
,delai_sep22,18.1
;

here is exactly what I want for result.

Capture d’écran 2022-10-12 000900.png

 

Thanks.


 

View solution in original post

2 REPLIES 2
Reeza
Super User

Two different methods illustrated below:

 

data students_mod;
set students;
if missing(type_college) then type_college = 'Total';
*get date value for sorting correctly if more dates included;
*may read correctly without compress if your locale is set for your language/location;
Date = input(compress(scan(name, -1, "_"), 'i'), monyy5.);
format date monyy5.;
run;


proc sgplot data=students_mod;
series y=col1 x=date / group = type_college markers datalabel=col1;
format date monyy5.;
keylegend /position=right;
run;

proc sgplot data=students_mod;
series y=col1 x=name / group=type_college datalabel=col1 ;
keylegend /position=right;
run;

@Child79 wrote:

Hello,

Here is my dataset. I have two categorical variables (type_college and name) and a numeric variable (COL1).

I don't know how to plot on the same graph the evolution curves of COL1 according to name for each type_college.

 

 

data students;
  infile datalines dlm=',' dsd;
  informat type_college $15.  name $15. ; 
input  type_college   name $  COL1 ;
datalines;
College private,delai_dec20,1.5
College private,delai_juin21,3.6
College private,delai_dec21,4.4
College private,delai_sep22,47.6
College public,delai_dec20,5.3
College public,delai_juin21,6
College public,delai_dec21,14.4
College public,delai_sep22,14.4
University,delai_dec20,11.1
University,delai_juin21,14.3
University,delai_dec21,14
University,delai_sep22,17.1
,delai_dec20,5.6
,delai_juin21,7.1
,delai_dec21,12
,delai_sep22,18.1
;

here is exactly what I want for result.

Capture d’écran 2022-10-12 000900.png

 

Thanks.


 

ballardw
Super User

If "total" is supposed to be the value for the missing university type then place a value or at least say so.

 

One way:

proc format;
value $misstype  (default=15)
' ' = 'Total';
run;
proc sgplot data=students;
   series x=name y=col1/ group= type_college
                 datalabel;
   format type_college $misstype. ;
run;

You will find in the long run that you will much better off using actual date values instead of things that hold dates such like your delai_dec20 because there are going to be times that you need to order the values and these will not sort correctly at all.

 

Graphing anything with a missing value is pretty much a problem to begin with. Much better off to supply an actual value so you know where it belongs on the graph.

 

Details about KEYLEND and style options to control appearance are left to you.

 


@Child79 wrote:

Hello,

Here is my dataset. I have two categorical variables (type_college and name) and a numeric variable (COL1).

I don't know how to plot on the same graph the evolution curves of COL1 according to name for each type_college.

 

 

data students;
  infile datalines dlm=',' dsd;
  informat type_college $15.  name $15. ; 
input  type_college   name $  COL1 ;
datalines;
College private,delai_dec20,1.5
College private,delai_juin21,3.6
College private,delai_dec21,4.4
College private,delai_sep22,47.6
College public,delai_dec20,5.3
College public,delai_juin21,6
College public,delai_dec21,14.4
College public,delai_sep22,14.4
University,delai_dec20,11.1
University,delai_juin21,14.3
University,delai_dec21,14
University,delai_sep22,17.1
,delai_dec20,5.6
,delai_juin21,7.1
,delai_dec21,12
,delai_sep22,18.1
;

here is exactly what I want for result.

Capture d’écran 2022-10-12 000900.png

 

Thanks.


 

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 466 views
  • 2 likes
  • 3 in conversation