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

Hello,

I would like to plot a graph with x-axis labelled as Date (Jan1994, Feb1994, March1994, ..., Dec2003) and y-axis labelled as Number of deaths (between 0-200). I am plotting data for 4 separate US states, but want them all to be included on the same plot. Ideally each state being represented by a different colour.

I would appreciate any help on what my SAS code should be for this to happen. Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Thanks. See if you can use this as a template.

 

data have;
input Year Month $ Illinois New Mexico Pennsylvania Texas;
datalines;
1994 Jan 70 11 60 168
1994 Feb 77 13 43 163
1994 Mar 104 6 46 185
1994 Apr 86 15 42 146
1994 May 98 11 63 170
1994 Jun 102 10 59 148
1994 Jul 90 9 59 187
1994 Aug 95 8 58 192
1994 Sep 73 1 58 155
1994 Oct 91 11 47 198
1994 Nov 87 9 61 167
1994 Dec 82 12 72 143
1995 Jan 64 7 49 147
1995 Feb 59 4 53 139
1995 Mar 68 7 54 132
1995 Apr 62 7 56 137
1995 May 78 4 37 133
1995 Jun 75 13 40 144
1995 Jul 78 13 50 167
1995 Aug 93 10 56 165
1995 Sep 82 11 65 128
1995 Oct 82 9 61 132
1995 Nov 66 8 42 127
1995 Dec 73 8 70 134
1996 Jan 69 13 57 131
1996 Feb 52 9 43 120
1996 Mar 60 17 55 102
1996 Apr 68 14 52 85
1996 May 68 12 47 158
1996 Jun 99 12 61 121
1996 Jul 89 7 54 123
1996 Aug 94 12 51 144
1996 Sep 58 11 51 117
1996 Oct 90 8 59 131
1996 Nov 56 12 60 101
1996 Dec 63 9 66 143
1997 Jan 66 8 53 103
1997 Feb 43 8 54 97
1997 Mar 52 11 52 122
1997 Apr 69 11 42 102
1997 May 59 10 44 106
1997 Jun 69 9 45 115
1997 Jul 86 6 48 118
1997 Aug 82 8 44 140
1997 Sep 71 12 56 115
1997 Oct 86 5 52 90
1997 Nov 65 7 49 101
1997 Dec 64 10 64 118
1998 Jan 54 17 56 133
1998 Feb 43 11 48 95
1998 Mar 62 11 44 96
1998 Apr 55 9 36 105
1998 May 76 10 51 124
1998 Jun 68 12 44 124
1998 Jul 65 13 49 121
1998 Aug 76 12 53 109
1998 Sep 58 11 40 117
1998 Oct 61 13 50 113
1998 Nov 62 10 47 94
1998 Dec 59 10 62 113
1999 Jan 59 5 56 126
1999 Feb 43 10 56 89
1999 Mar 46 8 32 92
1999 Apr 60 8 33 103
1999 May 63 16 46 107
1999 Jun 76 10 38 91
1999 Jul 59 10 39 92
1999 Aug 77 11 43 95
1999 Sep 56 16 47 107
1999 Oct 48 11 44 92
1999 Nov 59 15 48 96
1999 Dec 47 6 65 100
2000 Jan 49 12 53 106
2000 Feb 44 9 40 80
2000 Mar 46 7 36 94
2000 Apr 40 6 46 83
2000 May 50 13 40 103
2000 Jun 58 9 42 102
2000 Jul 84 8 56 113
2000 Aug 70 8 52 120
2000 Sep 64 6 45 109
2000 Oct 59 14 45 132
2000 Nov 60 9 43 86
2000 Dec 48 15 59 102
2001 Jan 44 9 5 107
2001 Feb 33 4 7 78
2001 Mar 40 6 3 102
2001 Apr 63 8 7 113
2001 May 46 6 3 101
2001 Jun 74 9 4 103
2001 Jul 78 7 7 125
2001 Aug 63 8 9 128
2001 Sep 74 5 11 113
2001 Oct 80 7 5 123
2001 Nov 68 5 3 104
2001 Dec 55 8 17 122
2002 Jan 51 12 50 121
2002 Feb 32 11 42 91
2002 Mar 44 16 49 111
2002 Apr 49 18 44 101
2002 May 50 3 48 103
2002 Jun 70 11 56 103
2002 Jul 80 15 47 130
2002 Aug 83 16 46 123
2002 Sep 75 9 55 118
2002 Oct 64 9 45 107
2002 Nov 46 8 61 87
2002 Dec 71 10 48 104
2003 Jan 41 12 52 92
2003 Feb 32 3 24 97
2003 Mar 55 6 48 117
2003 Apr 62 13 51 101
2003 May 61 6 44 141
2003 Jun 53 6 54 137
2003 Jul 76 12 50 127
2003 Aug 53 6 69 118
2003 Sep 58 11 48 117
2003 Oct 55 6 63 120
2003 Nov 55 8 51 117
2003 Dec 47 12 57 133
;

data plot(keep = city num date);
   set have;
   array c Illinois New Mexico Pennsylvania Texas;
   date = input(cats(month, year), monyy7.);

   do over c;
      city = vname(c);
      num = c;
      output;
   end;
   
   format date monyy7.;

   label num = "Number of Deaths" city = "City";
run;

title "Number of Deaths";
proc sgplot data = plot noautolegend;
   series x = date y = num / group = city;
   yaxis ranges = (0 - 200 1900 - 2100);
   keylegend / across = 1 location = inside position = nw;
run;
title;

 

Result:

 

 

Udklip.PNG

 

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Please provide sample data. Makes it much easier to provide a usable code answer 🙂

PeterClemmensen
Tourmaline | Level 20

Thanks. See if you can use this as a template.

 

data have;
input Year Month $ Illinois New Mexico Pennsylvania Texas;
datalines;
1994 Jan 70 11 60 168
1994 Feb 77 13 43 163
1994 Mar 104 6 46 185
1994 Apr 86 15 42 146
1994 May 98 11 63 170
1994 Jun 102 10 59 148
1994 Jul 90 9 59 187
1994 Aug 95 8 58 192
1994 Sep 73 1 58 155
1994 Oct 91 11 47 198
1994 Nov 87 9 61 167
1994 Dec 82 12 72 143
1995 Jan 64 7 49 147
1995 Feb 59 4 53 139
1995 Mar 68 7 54 132
1995 Apr 62 7 56 137
1995 May 78 4 37 133
1995 Jun 75 13 40 144
1995 Jul 78 13 50 167
1995 Aug 93 10 56 165
1995 Sep 82 11 65 128
1995 Oct 82 9 61 132
1995 Nov 66 8 42 127
1995 Dec 73 8 70 134
1996 Jan 69 13 57 131
1996 Feb 52 9 43 120
1996 Mar 60 17 55 102
1996 Apr 68 14 52 85
1996 May 68 12 47 158
1996 Jun 99 12 61 121
1996 Jul 89 7 54 123
1996 Aug 94 12 51 144
1996 Sep 58 11 51 117
1996 Oct 90 8 59 131
1996 Nov 56 12 60 101
1996 Dec 63 9 66 143
1997 Jan 66 8 53 103
1997 Feb 43 8 54 97
1997 Mar 52 11 52 122
1997 Apr 69 11 42 102
1997 May 59 10 44 106
1997 Jun 69 9 45 115
1997 Jul 86 6 48 118
1997 Aug 82 8 44 140
1997 Sep 71 12 56 115
1997 Oct 86 5 52 90
1997 Nov 65 7 49 101
1997 Dec 64 10 64 118
1998 Jan 54 17 56 133
1998 Feb 43 11 48 95
1998 Mar 62 11 44 96
1998 Apr 55 9 36 105
1998 May 76 10 51 124
1998 Jun 68 12 44 124
1998 Jul 65 13 49 121
1998 Aug 76 12 53 109
1998 Sep 58 11 40 117
1998 Oct 61 13 50 113
1998 Nov 62 10 47 94
1998 Dec 59 10 62 113
1999 Jan 59 5 56 126
1999 Feb 43 10 56 89
1999 Mar 46 8 32 92
1999 Apr 60 8 33 103
1999 May 63 16 46 107
1999 Jun 76 10 38 91
1999 Jul 59 10 39 92
1999 Aug 77 11 43 95
1999 Sep 56 16 47 107
1999 Oct 48 11 44 92
1999 Nov 59 15 48 96
1999 Dec 47 6 65 100
2000 Jan 49 12 53 106
2000 Feb 44 9 40 80
2000 Mar 46 7 36 94
2000 Apr 40 6 46 83
2000 May 50 13 40 103
2000 Jun 58 9 42 102
2000 Jul 84 8 56 113
2000 Aug 70 8 52 120
2000 Sep 64 6 45 109
2000 Oct 59 14 45 132
2000 Nov 60 9 43 86
2000 Dec 48 15 59 102
2001 Jan 44 9 5 107
2001 Feb 33 4 7 78
2001 Mar 40 6 3 102
2001 Apr 63 8 7 113
2001 May 46 6 3 101
2001 Jun 74 9 4 103
2001 Jul 78 7 7 125
2001 Aug 63 8 9 128
2001 Sep 74 5 11 113
2001 Oct 80 7 5 123
2001 Nov 68 5 3 104
2001 Dec 55 8 17 122
2002 Jan 51 12 50 121
2002 Feb 32 11 42 91
2002 Mar 44 16 49 111
2002 Apr 49 18 44 101
2002 May 50 3 48 103
2002 Jun 70 11 56 103
2002 Jul 80 15 47 130
2002 Aug 83 16 46 123
2002 Sep 75 9 55 118
2002 Oct 64 9 45 107
2002 Nov 46 8 61 87
2002 Dec 71 10 48 104
2003 Jan 41 12 52 92
2003 Feb 32 3 24 97
2003 Mar 55 6 48 117
2003 Apr 62 13 51 101
2003 May 61 6 44 141
2003 Jun 53 6 54 137
2003 Jul 76 12 50 127
2003 Aug 53 6 69 118
2003 Sep 58 11 48 117
2003 Oct 55 6 63 120
2003 Nov 55 8 51 117
2003 Dec 47 12 57 133
;

data plot(keep = city num date);
   set have;
   array c Illinois New Mexico Pennsylvania Texas;
   date = input(cats(month, year), monyy7.);

   do over c;
      city = vname(c);
      num = c;
      output;
   end;
   
   format date monyy7.;

   label num = "Number of Deaths" city = "City";
run;

title "Number of Deaths";
proc sgplot data = plot noautolegend;
   series x = date y = num / group = city;
   yaxis ranges = (0 - 200 1900 - 2100);
   keylegend / across = 1 location = inside position = nw;
run;
title;

 

Result:

 

 

Udklip.PNG

 

at2000
Calcite | Level 5

Thank you @PeterClemmensen for such an informative answer, that is a really great help.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 5 replies
  • 1289 views
  • 2 likes
  • 2 in conversation