Data visualization with SAS programming

Displaying Three Columns of Data in a Line Graph in SAS 9.2

Accepted Solution Solved
Reply
Super Contributor
Posts: 494
Accepted Solution

Displaying Three Columns of Data in a Line Graph in SAS 9.2

I have a dataset with three types of columns that is similar to the below example.  I want to display the three columns as three lines in a line graph with tooltips and display the line graph inside a portlet of Information Delivery Portal using SAS 9.2.  I’m not attached to the example I’m just posting it as a reference point.  What SAS method should I use to display the line graph? 


data sample;                                                                                                                           

   do Xvar=1 to 10;                                                                                                                    

      Yvar1=round(ranuni(0)*(30));                                                                                                     

      Yvar2=round(ranuni(0)*(70-40))+40;                                                                                               

      Yvar3=round(ranuni(0)*(100-70))+70;                                                                                              

      output;                                                                                                                          

   end;                                                                                                                                

run;                                                                                                                                   

                                                                                                                                       

/* Define the title */                                                                                                     

title1 "Use Solid-Filled Symbols with PROC GPLOT";                                                                                     

                                                                                                                                       

/* Define symbol characteristics */                                                                                                    

symbol1 interpol=join /*value=squarefilled*/   color=vibg height=2;                                                                        

symbol2 interpol=join /*value=trianglefilled*/ color=depk height=2;                                                                        

symbol3 interpol=join /*value=diamondfilled*/  color=mob  height=2;

                                                                                                                                       

/* Define legend characteristics */                                                                                                    

legend1 label=none frame;                                                                                                              

                                                                                                                                       

/* Define axis characteristics */                                                                                                      

axis1 label=("X Variable") minor=none offset=(1,1);                                                                                    

axis2 label=(angle=90 "Y Variable")                                                                                                    

      order=(0 to 100 by 10) minor=(n=1);                                                                                              

                                                                                                                                       

proc gplot data=sample;                                                                                                                

   plot (yvar1 yvar2 yvar3)*xvar / overlay legend=legend1                                                                              

                                   haxis=axis1 vaxis=axis2;                                                                            

run;


Accepted Solutions
Solution
‎07-28-2015 03:14 PM
Super Contributor
Posts: 494

Re: Displaying Three Columns of Data in a Line Graph in SAS 9.2

This combines the data into one column.

data sample;                                                                                                                           

   do Xvar=1 to 10;                                                                                                                    

      Yvar1=round(ranuni(0)*(30));                                                                                                     

      Yvar2=round(ranuni(0)*(70-40))+40;                                                                                               

      Yvar3=round(ranuni(0)*(100-70))+70;                                                                                              

      output;                                                                                                                          

   end;                                                                                                                                

run;                                                                                                                                  

proc print data= sample;

run;

proc summary data= sample;

  var Yvar1;

  output out = Yvar1Set sum = Yvar1;

run;

proc summary data= sample;

  var Yvar2;

  output out = Yvar2Set sum = Yvar2;

run;

proc summary data= sample;

  var Yvar3;

  output out = Yvar3Set sum = Yvar3;

run;

data Yvar1Set; set Yvar1Set (rename = (Yvar1 = mergedColumn)); length columnDisplay  $20; columnDisplay = "firstSet"; run;

data Yvar2Set; set Yvar2Set (rename = (Yvar2 = mergedColumn)); length columnDisplay  $20; columnDisplay = "secondSet"; run;

data Yvar3Set; set Yvar3Set (rename = (Yvar3 = mergedColumn)); length columnDisplay  $20; columnDisplay = "thirdSet"; run;

data combined (keep = mergedColumn columnDisplay); set Yvar1Set Yvar2Set Yvar3Set; run;

proc print data=combined;

run;

View solution in original post


All Replies
Super Contributor
Posts: 494

Re: Displaying Three Columns of Data in a Line Graph in SAS 9.2

If there is not a way to display the data directly is there a good way to reformat the data so that it is in one column?  Then I could index the column for tooltips.

Solution
‎07-28-2015 03:14 PM
Super Contributor
Posts: 494

Re: Displaying Three Columns of Data in a Line Graph in SAS 9.2

This combines the data into one column.

data sample;                                                                                                                           

   do Xvar=1 to 10;                                                                                                                    

      Yvar1=round(ranuni(0)*(30));                                                                                                     

      Yvar2=round(ranuni(0)*(70-40))+40;                                                                                               

      Yvar3=round(ranuni(0)*(100-70))+70;                                                                                              

      output;                                                                                                                          

   end;                                                                                                                                

run;                                                                                                                                  

proc print data= sample;

run;

proc summary data= sample;

  var Yvar1;

  output out = Yvar1Set sum = Yvar1;

run;

proc summary data= sample;

  var Yvar2;

  output out = Yvar2Set sum = Yvar2;

run;

proc summary data= sample;

  var Yvar3;

  output out = Yvar3Set sum = Yvar3;

run;

data Yvar1Set; set Yvar1Set (rename = (Yvar1 = mergedColumn)); length columnDisplay  $20; columnDisplay = "firstSet"; run;

data Yvar2Set; set Yvar2Set (rename = (Yvar2 = mergedColumn)); length columnDisplay  $20; columnDisplay = "secondSet"; run;

data Yvar3Set; set Yvar3Set (rename = (Yvar3 = mergedColumn)); length columnDisplay  $20; columnDisplay = "thirdSet"; run;

data combined (keep = mergedColumn columnDisplay); set Yvar1Set Yvar2Set Yvar3Set; run;

proc print data=combined;

run;

Super User
Posts: 11,134

Re: Displaying Three Columns of Data in a Line Graph in SAS 9.2

For most line plots I would tend to create a variable that indicates which series or group of data it belongs to instead of overlay.

data sample;                                                                                                                           

   do Xvar=1 to 10;   

     Group = 1;                                                                                                          

      Yval=round(ranuni(0)*(30));  

     output;

     group = 2;                                                                                                  

      Yval=round(ranuni(0)*(70-40))+40;  

     output;

     group = 3;                                                                                            

      Yval=round(ranuni(0)*(100-70))+70;                                                                                              

      output;                                                                                                                          

   end;                                                                                                                                

run;    

and display with

proc gplot data=sample;                                                                                                                

   plot yval*xvar = group /  legend=legend1                                                                              

                                   haxis=axis1 vaxis=axis2;                                                                            

run;

quit;

Or same data and use group =  option with SGPlot though Axis controls with 9.2 aren't quite as flexible as the traditional SAS/Graph.

Super Contributor
Posts: 494

Re: Displaying Three Columns of Data in a Line Graph in SAS 9.2

When I run that on 9.2 it creates the below unusable graph, without tooltipsGraph.png:

Super User
Posts: 11,134

Re: Displaying Three Columns of Data in a Line Graph in SAS 9.2

Since I don't see any lines then you didn't use your symbol statements. Tool tips I leave to others as I don't use them.

The reason I use an approach with assigning a categorical variable to define the data types is that it is way more manageable when more than 2 or 3 groups are around. Also if I discover than one series is dominating the data it is easy to plot by using a dataset option to exclude that series or two.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 453 views
  • 0 likes
  • 2 in conversation