Fluorite | Level 6

How to plot evolution curve of a numeric variable according to a categorical variable

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.

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

Re: How to plot evolution curve of a numeric variable according to a categorical variable

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;
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.

Thanks.

2 REPLIES 2
Super User

Re: How to plot evolution curve of a numeric variable according to a categorical variable

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;
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.

Thanks.

Super User

Re: How to plot evolution curve of a numeric variable according to a categorical variable

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.

Thanks.

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