BookmarkSubscribeRSS Feed
michokwu
Quartz | Level 8

Hello,

 

I have the following SAS dataset , original data was adjusted using 2010 as a baseline

YearTotalBachelorsDoctorateHSGNon_HSGMastersProfessionalSome_College
2010100100100100100100100100
201110010496989410796105
2012101108106949210997109
2013103114129949011399110
20141031171339289119101111
20151041241369085127103112
20161041261578883132111112
20171051291669077139122112

 

and this is my code

/* Plot the data */ 
proc sgplot data=ed_table; 
series x = Year y = Total / markers markerattrs=(symbol=plus) lineattrs=(pattern=solid);
series x = Year y = Non_HSG / markers markerattrs=(symbol=diamondfilled) lineattrs=(pattern=solid);
series x = Year y = HSG / markers markerattrs=(symbol=diamond) lineattrs=(pattern=solid);
series x = Year y = Some_College / markers markerattrs=(symbol=starfilled) lineattrs=(pattern=solid);
series x = Year y = Bachelors / markers markerattrs=(symbol=sqaurefilled) lineattrs=(pattern=solid);
series x = Year y = Masters / markers markerattrs=(symbol=trianglefilled) lineattrs=(pattern=solid);
series x = Year y = Professional / markers markerattrs=(symbol=homedownfilled) lineattrs=(pattern=solid);
series x = Year y = Doctorate / markers markerattrs=(symbol=circlefilled) lineattrs=(pattern=solid);
xaxis values= (2010 to 2017 by 1) label='5-Year Annual Estimate';
yaxis Label = 'Educational attainment adjusted for 2010 Baseline Year' Grid Values = (60 to 180 by 20);
title1 "Educational attainment for 25years and above";
title2 "Annual Data - Baseline 2010"; 

 

Please see attached the output I am getting. I don't know why the graph is turning out empty. 

 

Thank you.

 
9 REPLIES 9
PeterClemmensen
Tourmaline | Level 20

The code looks fine. The below code works for me?

 

data ed_table;
input Year Total Bachelors Doctorate HSG Non_HSG Masters Professional Some_College;
datalines;
2010 100 100 100 100 100 100 100 100
2011 100 104 96 98 94 107 96 105
2012 101 108 106 94 92 109 97 109
2013 103 114 129 94 90 113 99 110
2014 103 117 133 92 89 119 101 111
2015 104 124 136 90 85 127 103 112
2016 104 126 157 88 83 132 111 112
2017 105 129 166 90 77 139 122 112
;

title1 "Educational attainment for 25years and above";
title2 "Annual Data - Baseline 2010"; 
proc sgplot data=ed_table; 
series x = Year y = Total / markers markerattrs=(symbol=plus) lineattrs=(pattern=solid);
series x = Year y = Non_HSG / markers markerattrs=(symbol=diamondfilled) lineattrs=(pattern=solid);
series x = Year y = HSG / markers markerattrs=(symbol=diamond) lineattrs=(pattern=solid);
series x = Year y = Some_College / markers markerattrs=(symbol=starfilled) lineattrs=(pattern=solid);
series x = Year y = Bachelors / markers markerattrs=(symbol=sqaurefilled) lineattrs=(pattern=solid);
series x = Year y = Masters / markers markerattrs=(symbol=trianglefilled) lineattrs=(pattern=solid);
series x = Year y = Professional / markers markerattrs=(symbol=homedownfilled) lineattrs=(pattern=solid);
series x = Year y = Doctorate / markers markerattrs=(symbol=circlefilled) lineattrs=(pattern=solid);
xaxis values= (2010 to 2017 by 1) label='5-Year Annual Estimate';
yaxis Label = 'Educational attainment adjusted for 2010 Baseline Year' Grid Values = (60 to 180 by 20);
run;
title;
michokwu
Quartz | Level 8

Thank you so much. It works. Does that mean we can't plot data using SAS dataset? How do we use datalines when we have a large data set?

Reeza
Super User
The data lines statements only creates the data set. The SGPLOT is using the data set. Whatever your issue is, is different, and the log will likely tell you why.
Reeza
Super User

Please share the log from that portion of code.

 


@michokwu wrote:

Hello,

 

I have the following SAS dataset , original data was adjusted using 2010 as a baseline

Year Total Bachelors Doctorate HSG Non_HSG Masters Professional Some_College
2010 100 100 100 100 100 100 100 100
2011 100 104 96 98 94 107 96 105
2012 101 108 106 94 92 109 97 109
2013 103 114 129 94 90 113 99 110
2014 103 117 133 92 89 119 101 111
2015 104 124 136 90 85 127 103 112
2016 104 126 157 88 83 132 111 112
2017 105 129 166 90 77 139 122 112

 

and this is my code

/* Plot the data */ 
proc sgplot data=ed_table; 
series x = Year y = Total / markers markerattrs=(symbol=plus) lineattrs=(pattern=solid);
series x = Year y = Non_HSG / markers markerattrs=(symbol=diamondfilled) lineattrs=(pattern=solid);
series x = Year y = HSG / markers markerattrs=(symbol=diamond) lineattrs=(pattern=solid);
series x = Year y = Some_College / markers markerattrs=(symbol=starfilled) lineattrs=(pattern=solid);
series x = Year y = Bachelors / markers markerattrs=(symbol=sqaurefilled) lineattrs=(pattern=solid);
series x = Year y = Masters / markers markerattrs=(symbol=trianglefilled) lineattrs=(pattern=solid);
series x = Year y = Professional / markers markerattrs=(symbol=homedownfilled) lineattrs=(pattern=solid);
series x = Year y = Doctorate / markers markerattrs=(symbol=circlefilled) lineattrs=(pattern=solid);
xaxis values= (2010 to 2017 by 1) label='5-Year Annual Estimate';
yaxis Label = 'Educational attainment adjusted for 2010 Baseline Year' Grid Values = (60 to 180 by 20);
title1 "Educational attainment for 25years and above";
title2 "Annual Data - Baseline 2010"; 

 

Please see attached the output I am getting. I don't know why the graph is turning out empty. 

 

Thank you.

 

 

michokwu
Quartz | Level 8

Sorry, I don't have the log details anymore. I already updated the code using @PeterClemmensen 's suggestion.

 

I can go back, try using my initial input and revert

ballardw
Super User

It is best to provide example data in the form of a data step so we can test code against your values.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

Since you image is not blank but appears to have at least "Total" "Some_college" and doctorate for the year 2010, and total for 2011, one starts to suspect the actual content of your data. Possibly the ED_TABLE plotted does not have as many rows as you show.

 

It might be a good idea to show the log with the entire proc step including notes about number of observations used and such.

 

BTW a typical way to do this instead of having different variables for your Total through Some_college data would be to have the data with a single variable that holds the type, i.e. Total through Some_college, a single value and a GROUP= to create the different graph properties such as

 

proc sgplot data=ed_table; 
series x = Year y = value / group=Groupvar markers ;
run;
michokwu
Quartz | Level 8

data WORK.ED_TABLE;
infile datalines dsd truncover;
input Year:$8. Total:$3. Bachelors:$3. Doctorate:$3. HSG:$3. Non_HSG:$3. Masters:$3. Professional:$3. Some_College:$3.;
label Year="NAME OF FORMER VARIABLE";
datalines;
2010 100 100 100 100 100 100 100 100
2011 100 104 96 98 94 107 96 105
2012 101 108 106 94 92 109 97 109
2013 103 114 129 94 90 113 99 110
2014 103 117 133 92 89 119 101 111
2015 104 124 136 90 85 127 103 112
2016 104 126 157 88 83 132 111 112
2017 105 129 166 90 77 139 122 112
;;;;
NOTE: There were 8 observations read from the data set WORK.ED_TABLE.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

Reeza
Super User
That step is creating the data. You should not need it, you should be using your own data set called ed_table.
ballardw
Super User

@michokwu wrote:

data WORK.ED_TABLE;
infile datalines dsd truncover;
input Year:$8. Total:$3. Bachelors:$3. Doctorate:$3. HSG:$3. Non_HSG:$3. Masters:$3. Professional:$3. Some_College:$3.;
label Year="NAME OF FORMER VARIABLE";
datalines;
2010 100 100 100 100 100 100 100 100
2011 100 104 96 98 94 107 96 105
2012 101 108 106 94 92 109 97 109
2013 103 114 129 94 90 113 99 110
2014 103 117 133 92 89 119 101 111
2015 104 124 136 90 85 127 103 112
2016 104 126 157 88 83 132 111 112
2017 105 129 166 90 77 139 122 112
;;;;
NOTE: There were 8 observations read from the data set WORK.ED_TABLE.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


Series plots are going to expect NUMERIC values for variables used in X= and Y=. Your data step creates only CHARACTER values.

Your Year variable only has 4 digits, reading with 8 means that TOTAL is not what you think it might be.

DSD is also not needed.

data WORK.ED_TABLE;
infile datalines  truncover;
input Year: 4. Total: 3. Bachelors: 3. Doctorate: 3. HSG: 3. Non_HSG: 3. Masters: 3. Professional: 3. Some_College: 3.;
label Year="NAME OF FORMER VARIABLE";
datalines;
2010 100 100 100 100 100 100 100 100
2011 100 104 96 98 94 107 96 105
2012 101 108 106 94 92 109 97 109
2013 103 114 129 94 90 113 99 110
2014 103 117 133 92 89 119 101 111
2015 104 124 136 90 85 127 103 112
2016 104 126 157 88 83 132 111 112
2017 105 129 166 90 77 139 122 112
;;;;

proc sgplot data=work.ed_table; 
series x = Year y = Total / markers markerattrs=(symbol=plus) lineattrs=(pattern=solid);
series x = Year y = Non_HSG / markers markerattrs=(symbol=diamondfilled) lineattrs=(pattern=solid);
series x = Year y = HSG / markers markerattrs=(symbol=diamond) lineattrs=(pattern=solid);
series x = Year y = Some_College / markers markerattrs=(symbol=starfilled) lineattrs=(pattern=solid);
series x = Year y = Bachelors / markers markerattrs=(symbol=sqaurefilled) lineattrs=(pattern=solid);
series x = Year y = Masters / markers markerattrs=(symbol=trianglefilled) lineattrs=(pattern=solid);
series x = Year y = Professional / markers markerattrs=(symbol=homedownfilled) lineattrs=(pattern=solid);
series x = Year y = Doctorate / markers markerattrs=(symbol=circlefilled) lineattrs=(pattern=solid);
xaxis values= (2010 to 2017 by 1) label='5-Year Annual Estimate';
yaxis Label = 'Educational attainment adjusted for 2010 Baseline Year' Grid Values = (60 to 180 by 20);
title1 "Educational attainment for 25years and above";
title2 "Annual Data - Baseline 2010"; 
run;

Yields:

SGPlot.png

 

So, there must be something unexpected about your original data set. Note, my colors will likely vary from yours due to my use of the MEADOW style.

 

And for further consideration:

proc transpose data=work.ed_table
     out=work.ed_trans name= groupvar prefix=value;
by year;
var  Total Bachelors Doctorate HSG Non_HSG Masters Professional Some_College;
run;

proc sgplot data=work.ed_trans;
   series x=year y=value1/group=groupvar markers;
   xaxis values= (2010 to 2017 by 1) label='5-Year Annual Estimate';
   yaxis Label = 'Educational attainment adjusted for 2010 Baseline Year' Grid Values = (60 to 180 by 20);
   title1 "Educational attainment for 25years and above";
   title2 "Annual Data - Baseline 2010";
   label groupvar='Education Attaintment'; 
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 9 replies
  • 1941 views
  • 0 likes
  • 4 in conversation