Data visualization with SAS programming

SAS Graph, Align axis with lattice rows

Reply
Contributor
Posts: 25

SAS Graph, Align axis with lattice rows

I'm really struggling myself with this problem, I really can't find a solution and I hope that, posting here, someone will help.

 

The problem is that with this 2-lattice-rows template I can't align the axis.

BIG PROBLEM

 

Now I detail everything I did with code to reproduce each step:

I have this plot:

First_plot

 

Here the code both for the graph and for the sample dataset (it's a simple version of this:http://support.sas.com/kb/39/092.html).

Sample dataset:

 

data immune;
   format sival f6.3;
   input trt $ 1-8 cyc $ 10-18 pt lbparm $ xval sival;
   cards;
Drug A   Cycle 1   1   C3  1   1.120
Drug A   Cycle 1   1   C4  1   0.147
Drug A   Cycle 1   1   C3  2   1.080
Drug A   Cycle 1   1   C4  2   0.131
Drug A   Cycle 1   1   C3  3   0.887
Drug A   Cycle 1   1   C4  3   0.113
Drug A   Cycle 2   1   C3  4   1.440
Drug A   Cycle 2   1   C4  4   0.278
Drug A   Cycle 2   1   C3  5   1.180
Drug A   Cycle 2   1   C4  5   0.234
Drug A   Cycle 2   1   C3  6   1.360
Drug A   Cycle 2   1   C4  6   0.281
Drug A   Cycle 3   1   C3  7   1.190
Drug A   Cycle 3   1   C4  7   0.282
Drug A   Cycle 3   1   C3  8   1.000
Drug A   Cycle 3   1   C4  8   0.228
Drug A   Cycle 3   1   C3  9   1.040
Drug A   Cycle 3   1   C4  9   0.228
Drug A   Cycle 4   1   C3 10   0.917
Drug A   Cycle 4   1   C4 10   0.163
Drug A   Cycle 4   1   C3 11   0.789
Drug A   Cycle 4   1   C4 11   0.136
Drug A   Cycle 4   1   C3 12   0.861
Drug A   Cycle 4   1   C4 12   0.148
Drug A   Cycle 1   2   C3  1   1.180
Drug A   Cycle 1   2   C4  1   0.264
Drug A   Cycle 1   2   C3  2   0.942
Drug A   Cycle 1   2   C4  2   0.184
Drug A   Cycle 1   2   C3  3   1.010
Drug A   Cycle 1   2   C4  3   0.160
Drug A   Cycle 2   2   C3  4   1.050
Drug A   Cycle 2   2   C4  4   0.134
Drug A   Cycle 2   2   C3  5   0.980
Drug A   Cycle 2   2   C4  5   0.120
Drug A   Cycle 2   2   C3  6   1.020
Drug A   Cycle 2   2   C4  6   0.126
Drug A   Cycle 3   2   C3  7   0.961
Drug A   Cycle 3   2   C4  7   0.110
Drug A   Cycle 3   2   C3  8   0.859
Drug A   Cycle 3   2   C4  8   0.091
Drug A   Cycle 3   2   C3  9   0.928
Drug A   Cycle 3   2   C4  9   0.097
Drug A   Cycle 4   2   C3 10   1.380
Drug A   Cycle 4   2   C4 10   0.330
Drug A   Cycle 4   2   C3 11   1.210
Drug A   Cycle 4   2   C4 11   0.281
Drug A   Cycle 4   2   C3 12   1.180
Drug A   Cycle 4   2   C4 12   0.278
Drug A   Cycle 1   3   C3  1   1.180
Drug A   Cycle 1   3   C4  1   0.269
Drug A   Cycle 1   3   C3  2   1.010
Drug A   Cycle 1   3   C4  2   0.213
Drug A   Cycle 1   3   C3  3   1.040
Drug A   Cycle 1   3   C4  3   0.200
Drug A   Cycle 2   3   C3  4   1.200
Drug A   Cycle 2   3   C4  4   0.332
Drug A   Cycle 2   3   C4  5   0.371
Drug A   Cycle 2   3   C4  6   0.316
Drug A   Cycle 3   3   C4  7   0.271
Drug A   Cycle 3   3   C3  8   1.050
Drug A   Cycle 3   3   C4  8   0.246
Drug A   Cycle 3   3   C3  9   1.100
Drug A   Cycle 3   3   C4  9   0.248
Drug A   Cycle 4   3   C3 10   1.090
Drug A   Cycle 4   3   C4 10   0.234
Drug A   Cycle 4   3   C3 11   0.937
Drug A   Cycle 4   3   C3 12   0.980
Drug A   Cycle 1   4   C3  1   1.220
Drug A   Cycle 1   4   C4  1   0.182
Drug A   Cycle 1   4   C3  2   0.983
Drug A   Cycle 1   4   C4  2   0.132
Drug A   Cycle 1   4   C3  3   0.979
Drug A   Cycle 1   4   C4  3   0.128
Drug A   Cycle 2   4   C3  4   1.190
Drug A   Cycle 2   4   C4  4   0.134
Drug A   Cycle 2   4   C3  5   1.010
Drug A   Cycle 2   4   C4  5   0.076
Drug A   Cycle 2   4   C3  6   1.100
Drug A   Cycle 2   4   C4  6   0.083
Drug A   Cycle 3   4   C3  7   1.140
Drug A   Cycle 3   4   C4  7   0.108
Drug A   Cycle 3   4   C3  8   1.140
Drug A   Cycle 3   4   C4  8   0.104
Drug A   Cycle 3   4   C3  9   1.120
Drug A   Cycle 3   4   C4  9   0.080
;
run;

proc sort data=immune out=sasuser.immune;
   by pt;
run;

Now the template code for the graph:

proc template;
  define statgraph gsv00251;
    begingraph / designwidth=7in designheight=4.5in;
      entrytitle 'Immunology Profile by Treatment';
      layout gridded;
        layout datalattice rowvar=lbparm /
               headerlabeldisplay=value includemissingclass=false
               columnaxisopts=(label="Cycle Day" griddisplay=on type=discrete
               discreteopts=(tickdisplaylist=
               ("0" "15" "30" "0" "15" "30" "0" "15" "30" "0" "15" "30"))  
               offsetmin = .03 offsetmax = .03)
               rowaxisopts=(offsetmax=.1 label="Values Converted to SI Units "
               griddisplay=on) rowdatarange=union;
        layout prototype;
          blockplot x=xval block=cyc / datatransparency = .75
                                       display=(outline fill ) 
                                       name="block" filltype=alternate;
          seriesplot x=xval y=sival / group=pt index=pt name='a'
                                      display=all lineattrs=(pattern=1 thickness=2) 
                                      markerattrs=(symbol=circlefilled size=8);    
        endlayout;
        endlayout;
        entry ' ';
        discretelegend 'a' / title='Patient' across=8;
      endlayout; 
    endgraph;
  end;
run;

Now I'd like to add some information on the top of each block, so I went through some searches on the web and I found out that the best way to achieve this result is to change the proc template, adding 2 lattice rows:

 

1) the first lattice row containing a blockplot with these informations like in this plot https://support.sas.com/documentation/cdl/en/grstatug/62464/HTML/default/viewer.htm#n07sfa0fbx6yh5n1... (the one with boxplots and statistics, the second example).

2) the second lattice row containing the previously posted plot.

 

So I created this raw sample dataset:

 

data firstrow;
length ROW $20 TITLE $20 REASON $50 CHAR $20 VAR $20;
infile datalines dlm=',';
input ROW TITLE REASON CHAR VAR;
datalines;
ROW 1,ROW 1,FIRST REASON,FIRST ROW,FIRST VAR,
ROW 2,ROW 2,SECOND REASON,SECOND ROW,SECOND VAR,
ROW 3,ROW 3,THIRD REASON,THIRD ROW,THIRD VAR,
ROW 4,ROW 4,FOURTH REASON,FOURTH ROW,FOURTH VAR,
;
proc transpose data=firstrow out=firstrow_;
by row;
var title reason char var;
run;

and merged (no by) it with the previous dataset:

 

proc sort data=immune out=immune;
   by pt;
run;

data immune;
merge immune firstrow_;
run;

then modified the proc template adding layout lattice and the blockplot.

proc template;
  define statgraph gsv00251;
    begingraph / designwidth=7in designheight=4.5in;
      entrytitle 'Immunology Profile by Treatment';

     layout lattice / columns=1 rowweights=(.15 .85);
              blockplot x=row block=col1  / class=_name_
                        datatransparency = .75
                        display=(outline fill values label)
                        name="stats" filltype=alternate 
                        valuehalign=center
                        includemissingclass=false
                        labelattrs=GraphDataText valueattrs=GraphDataText ;
      layout gridded;
        layout datalattice rowvar=lbparm /
               headerlabeldisplay=value includemissingclass=false
               columnaxisopts=(label="Cycle Day" griddisplay=on type=discrete
               discreteopts=(tickdisplaylist=
               ("0" "15" "30" "0" "15" "30" "0" "15" "30" "0" "15" "30"))  
               offsetmin = .03 offsetmax = .03)
               rowaxisopts=(offsetmax=.1 label="Values Converted to SI Units "
               griddisplay=on) rowdatarange=union;
        layout prototype;
          blockplot x=xval block=cyc / datatransparency = .75
                                       display=(outline fill ) 
                                       name="block" filltype=alternate;
          seriesplot x=xval y=sival / group=pt index=pt name='a'
                                      display=all lineattrs=(pattern=1 thickness=2) 
                                      markerattrs=(symbol=circlefilled size=8);    
        endlayout;
        endlayout;
        entry ' ';
        discretelegend 'a' / title='Patient' across=8;
      endlayout; 

    endlayout;

The result is good but not least, I mean, the column axis is not aligned with the two plots, the result is the first plot posted.

There are basically 2 issues: header labels on the right and axis label on the left. Howe can I change this plot, to gain the correct result? (axis aligned)

 

Since I posted a lot of code, here you will find only the final version of all this:

 data immune;
   format sival f6.3;
   input trt $ 1-8 cyc $ 10-18 pt lbparm $ xval sival;
   cards;
Drug A   Cycle 1   1   C3  1   1.120
Drug A   Cycle 1   1   C4  1   0.147
Drug A   Cycle 1   1   C3  2   1.080
Drug A   Cycle 1   1   C4  2   0.131
Drug A   Cycle 1   1   C3  3   0.887
Drug A   Cycle 1   1   C4  3   0.113
Drug A   Cycle 2   1   C3  4   1.440
Drug A   Cycle 2   1   C4  4   0.278
Drug A   Cycle 2   1   C3  5   1.180
Drug A   Cycle 2   1   C4  5   0.234
Drug A   Cycle 2   1   C3  6   1.360
Drug A   Cycle 2   1   C4  6   0.281
Drug A   Cycle 3   1   C3  7   1.190
Drug A   Cycle 3   1   C4  7   0.282
Drug A   Cycle 3   1   C3  8   1.000
Drug A   Cycle 3   1   C4  8   0.228
Drug A   Cycle 3   1   C3  9   1.040
Drug A   Cycle 3   1   C4  9   0.228
Drug A   Cycle 4   1   C3 10   0.917
Drug A   Cycle 4   1   C4 10   0.163
Drug A   Cycle 4   1   C3 11   0.789
Drug A   Cycle 4   1   C4 11   0.136
Drug A   Cycle 4   1   C3 12   0.861
Drug A   Cycle 4   1   C4 12   0.148
Drug A   Cycle 1   2   C3  1   1.180
Drug A   Cycle 1   2   C4  1   0.264
Drug A   Cycle 1   2   C3  2   0.942
Drug A   Cycle 1   2   C4  2   0.184
Drug A   Cycle 1   2   C3  3   1.010
Drug A   Cycle 1   2   C4  3   0.160
Drug A   Cycle 2   2   C3  4   1.050
Drug A   Cycle 2   2   C4  4   0.134
Drug A   Cycle 2   2   C3  5   0.980
Drug A   Cycle 2   2   C4  5   0.120
Drug A   Cycle 2   2   C3  6   1.020
Drug A   Cycle 2   2   C4  6   0.126
Drug A   Cycle 3   2   C3  7   0.961
Drug A   Cycle 3   2   C4  7   0.110
Drug A   Cycle 3   2   C3  8   0.859
Drug A   Cycle 3   2   C4  8   0.091
Drug A   Cycle 3   2   C3  9   0.928
Drug A   Cycle 3   2   C4  9   0.097
Drug A   Cycle 4   2   C3 10   1.380
Drug A   Cycle 4   2   C4 10   0.330
Drug A   Cycle 4   2   C3 11   1.210
Drug A   Cycle 4   2   C4 11   0.281
Drug A   Cycle 4   2   C3 12   1.180
Drug A   Cycle 4   2   C4 12   0.278
Drug A   Cycle 1   3   C3  1   1.180
Drug A   Cycle 1   3   C4  1   0.269
Drug A   Cycle 1   3   C3  2   1.010
Drug A   Cycle 1   3   C4  2   0.213
Drug A   Cycle 1   3   C3  3   1.040
Drug A   Cycle 1   3   C4  3   0.200
Drug A   Cycle 2   3   C3  4   1.200
Drug A   Cycle 2   3   C4  4   0.332
Drug A   Cycle 2   3   C4  5   0.371
Drug A   Cycle 2   3   C4  6   0.316
Drug A   Cycle 3   3   C4  7   0.271
Drug A   Cycle 3   3   C3  8   1.050
Drug A   Cycle 3   3   C4  8   0.246
Drug A   Cycle 3   3   C3  9   1.100
Drug A   Cycle 3   3   C4  9   0.248
Drug A   Cycle 4   3   C3 10   1.090
Drug A   Cycle 4   3   C4 10   0.234
Drug A   Cycle 4   3   C3 11   0.937
Drug A   Cycle 4   3   C3 12   0.980
Drug A   Cycle 1   4   C3  1   1.220
Drug A   Cycle 1   4   C4  1   0.182
Drug A   Cycle 1   4   C3  2   0.983
Drug A   Cycle 1   4   C4  2   0.132
Drug A   Cycle 1   4   C3  3   0.979
Drug A   Cycle 1   4   C4  3   0.128
Drug A   Cycle 2   4   C3  4   1.190
Drug A   Cycle 2   4   C4  4   0.134
Drug A   Cycle 2   4   C3  5   1.010
Drug A   Cycle 2   4   C4  5   0.076
Drug A   Cycle 2   4   C3  6   1.100
Drug A   Cycle 2   4   C4  6   0.083
Drug A   Cycle 3   4   C3  7   1.140
Drug A   Cycle 3   4   C4  7   0.108
Drug A   Cycle 3   4   C3  8   1.140
Drug A   Cycle 3   4   C4  8   0.104
Drug A   Cycle 3   4   C3  9   1.120
Drug A   Cycle 3   4   C4  9   0.080
;
run;


data firstrow;
length ROW $20 TITLE $20 REASON $50 CHAR $20 VAR $20;
infile datalines dlm=',';
input ROW TITLE REASON CHAR VAR;
datalines;
ROW 1,ROW 1,FIRST REASON,FIRST ROW,FIRST VAR,
ROW 2,ROW 2,SECOND REASON,SECOND ROW,SECOND VAR,
ROW 3,ROW 3,THIRD REASON,THIRD ROW,THIRD VAR,
ROW 4,ROW 4,FOURTH REASON,FOURTH ROW,FOURTH VAR,
;

proc transpose data=firstrow out=firstrow_;
by row;
var title reason char var;
run;

proc sort data=immune out=immune;
   by pt;
run;

data immune;
merge immune firstrow_;
run;

proc template;
  define statgraph gsv00251;
    begingraph / designwidth=7in designheight=4.5in;
      entrytitle 'Immunology Profile by Treatment';

     layout lattice / columns=1 rowweights=(.15 .85);
                columnaxes;
                    columnaxis / display=(ticks tickvalues);
                endcolumnaxes;



              blockplot x=row block=col1  / class=_name_
                        datatransparency = .75
                        display=(outline fill values label)
                        name="stats" filltype=alternate 
                        valuehalign=center
                        includemissingclass=false
                        labelattrs=GraphDataText valueattrs=GraphDataText ;
      layout gridded;
        layout datalattice rowvar=lbparm /
               headerlabeldisplay=value includemissingclass=false
               columnaxisopts=(label="Cycle Day" griddisplay=on type=discrete
               discreteopts=(tickdisplaylist=
               ("0" "15" "30" "0" "15" "30" "0" "15" "30" "0" "15" "30"))  
               offsetmin = .03 offsetmax = .03)
               rowaxisopts=(offsetmax=.1 label="Values Converted to SI Units "
               griddisplay=on) rowdatarange=union;
        layout prototype;
          blockplot x=xval block=cyc / datatransparency = .75
                                       display=(outline fill ) 
                                       name="block" filltype=alternate;
          seriesplot x=xval y=sival / group=pt index=pt name='a'
                                      display=all lineattrs=(pattern=1 thickness=2) 
                                      markerattrs=(symbol=circlefilled size=8);    
        endlayout;
        endlayout;
        entry ' ';
        discretelegend 'a' / title='Patient' across=8;
      endlayout; 

    endlayout;

    endgraph;
  end;
run;
ods listing close;
ods html image_dpi=100 file='Immunology.html' path='.';
ods graphics / reset noborder width=600px height=400px 
  imagename='ClinicalHandout_Immunology' imagefmt=gif noscale;

proc sgrender data=immune template=gsv00251; 
run;
ods html close;
ods listing;

Thank you.

SAS Super FREQ
Posts: 1,141

Re: SAS Graph, Align axis with lattice rows

When you use an outer LAYOUT LATTICE container with separate cells for the block plot and the DATAPANEL graph, there is no  alignment between the axes of the contained plots.  The plots do not know about each other.

 

The BLOCKPLOT in the panel has X=XVAL while the BLOCKPLOT at the top has X=ROW.  These are independent variables.  Also, the top graph is stand alone, and does not have need for reserving space for the row headers in the lower section.

 

The best way to do this is to avoid using the data panel.  Use one LAYOUT LATTICE with three rows. Bottom two rows will have the series plots for 'C3' and 'C4' data.  You can use expressions to pull out only data for one value of LBPARM.  Use INSET or ROWHWADER to place the class value.  Top row will have the statistics using a block plot or AxisTable.  make sure the x variables are same or similar.

 

It is useful to know what release of SAS you are using.  Will be easier with SAS 9.4M3.  

 

 

Contributor
Posts: 25

Re: SAS Graph, Align axis with lattice rows

sadly 9.2M0, tomorrow I will try your solution, but I'm not so confident to get the unique lineplot without using the datalattice. I will update you, Thank you for the moment!
Super Contributor
Posts: 252

Re: SAS Graph, Align axis with lattice rows

Hello,

 

Below is a template that you can use to align the header information with the cycles, and I believe this should work in 9.2. However this has been done manually by using the referenceline and scatterplot statements. Also more work needs to be done on adding information for Cycle 3 and Cycle 4, but this can be worked out quite easily by just using the correct filtering and the correct x-value. Also more work needs to be done on including the variable row header and the fill background color within the table if necessary. I believe one option to do the fill color is by using the band statement.

 

Please let me know if you have any questions.

proc template;
  define statgraph gsv00251;
    begingraph / designwidth=7in designheight=4.5in;
      entrytitle 'Immunology Profile by Treatment';

     layout lattice / columns=1 rowweights=(.15 .85);
                columnaxes;
                    columnaxis / display=(ticks tickvalues);
                endcolumnaxes;
             
			  layout overlay / yaxisopts = (display = (line)) xaxisopts = (offsetmin = .03 offsetmax = .03 display = (line));

              scatterplot x=xval y = pt /* So that Y goes from 1 to 4 */ / markerattrs = (size = 0);
			  /* Table for Labels */

			  scatterplot x = eval(ifn(row = "ROW 1" and _NAME_ = "TITLE", 3, .)) y = eval(ifn(row = "ROW 1" and _NAME_ = "TITLE", 4, .)) / markercharacter = col1;
			  scatterplot x = eval(ifn(row = "ROW 1" and _NAME_ = "REASON", 3, .)) y = eval(ifn(row = "ROW 1" and _NAME_ = "REASON", 3, .)) / markercharacter = col1;
			  scatterplot x = eval(ifn(row = "ROW 1" and _NAME_ = "CHAR", 3, .)) y = eval(ifn(row = "ROW 1" and _NAME_ = "CHAR", 2, .)) / markercharacter = col1;
			  scatterplot x = eval(ifn(row = "ROW 1" and _NAME_ = "VAR", 3, .)) y = eval(ifn(row = "ROW 1" and _NAME_ = "VAR", 1, .)) / markercharacter = col1;

			  scatterplot x = eval(ifn(row = "ROW 2" and _NAME_ = "TITLE", 5.7, .)) y = eval(ifn(row = "ROW 2" and _NAME_ = "TITLE", 4, .)) / markercharacter = col1;
			  scatterplot x = eval(ifn(row = "ROW 2" and _NAME_ = "REASON", 5.7, .)) y = eval(ifn(row = "ROW 2" and _NAME_ = "REASON", 3, .)) / markercharacter = col1;
			  scatterplot x = eval(ifn(row = "ROW 2" and _NAME_ = "CHAR", 5.7, .)) y = eval(ifn(row = "ROW 2" and _NAME_ = "CHAR", 2, .)) / markercharacter = col1;
			  scatterplot x = eval(ifn(row = "ROW 2" and _NAME_ = "VAR", 5.7, .)) y = eval(ifn(row = "ROW 2" and _NAME_ = "VAR", 1, .)) / markercharacter = col1;



			  referenceline x =  4.25 / lineattrs = (color = black);
			  referenceline x =  7.05 / lineattrs = (color = black);
			  referenceline x =  9.85 / lineattrs = (color = black);
			  referenceline x = 12.5 / lineattrs = (color = black);
              *blockplot x=row block=col1  / class=_name_
                        datatransparency = .75
                        display=(outline fill values label)
                        name="stats" filltype=alternate 
                        valuehalign=center
                        includemissingclass=false
                        labelattrs=GraphDataText valueattrs=GraphDataText ;

			   endlayout;

      layout gridded;
        layout datalattice rowvar=lbparm /
               headerlabeldisplay=value includemissingclass=false
               columnaxisopts=(label="Cycle Day" griddisplay=on type=discrete
               discreteopts=(tickdisplaylist=
               ("0" "15" "30" "0" "15" "30" "0" "15" "30" "0" "15" "30"))  
               offsetmin = .03 offsetmax = .03)
               rowaxisopts=(offsetmax=.1 label="Values Converted to SI Units "
               griddisplay=on) rowdatarange=union;
        layout prototype;
          blockplot x=xval block=cyc / datatransparency = .75
                                       display=(outline fill ) 
                                       name="block" filltype=alternate;
          seriesplot x=xval y=sival / group=pt index=pt name='a'
                                      display=all lineattrs=(pattern=1 thickness=2) 
                                      markerattrs=(symbol=circlefilled size=8);    
        endlayout;
        endlayout;
        entry ' ';
        discretelegend 'a' / title='Patient' across=8;
      endlayout; 

    endlayout;

    endgraph;
  end;
run;

 


ClinicalHandout_Immunology.png
Contributor
Posts: 25

Re: SAS Graph, Align axis with lattice rows

Thank you djrisks, great idea, but this won't work in my case since the template should be dynamic (4 to 12 columns) and your template can't change on the data.
Anyway today I was extremely busy with other tasks but I will try Sanjay's solution. I will try again and I will appreciate your help if I will need some.
Thank you again Smiley Happy
Super Contributor
Posts: 252

Re: SAS Graph, Align axis with lattice rows

That's fine. Okay, I understand. It's a interesting problem! Please post the answer too, after you have implemented Sanjay's solution! :-)

Contributor
Posts: 25

Re: SAS Graph, Align axis with lattice rows

OK, here again and almost near the solution Robot Happy

 

I'm gone through Sanjay's solution (can't say how much I'm thankful to him).

 

lasdash.gif

 

Great! Don't you think so?

Now my problems are:
1) why rowweight option for layout lattice is not working? A message is shown in the log saying that it is invalid and default will be used (four plots with same height). I want first and last plot to be far more small than middle ones. I tried with rowweight=(.15 .35 .35 .15)
2) How to set the maximum discrete value shown? I had to add a blank value as 12 otherwise the plot would've cut exactly on 12 since the latest value was 11. But now that I set it as 12 there are some space at the end of the plot (I shown it cutting the latest block) .

 

Here the code, hopefully it will help someone also outside from this question.

 

data immune;
length cycle $10 xval yC3 yC4 8.;
infile datalines dlm=',';
input cycle $ xval yC3 yC4;
datalines;
Cycle1,1,1.080,0.131,
Cycle1,2,0.887,0.113,
Cycle2,3,.,.,
Cycle2,4,1.180,0.234,
Cycle2,5,1.360,0.281,
Cycle3,6,.,.,
Cycle3,7,1.000,0.228,
Cycle3,8,1.040,0.228,
Cycle4,9,.,.,
Cycle4,10,0.789,0.136,
Cycle4,11,0.861,0.148,
Cycle4,12,.,.,
;
run;


data firstrow;
length XAR 8. ROW $20 TITLE $20 REASON $50 CHAR $20 VAR $20;
infile datalines dlm=',';
input XAR ROW TITLE REASON CHAR VAR;
datalines;
1,ROW 1,ROW 1,FIRST REASON,FIRST ROW,FIRST VAR,
3,ROW 2,ROW 2,SECOND REASON,SECOND ROW,SECOND VAR,
6,ROW 3,ROW 3,THIRD REASON,THIRD ROW,THIRD VAR,
9,ROW 4,ROW 4,FOURTH REASON,FOURTH ROW,FOURTH VAR,
;
proc sort; by xar row; run;
data label;
length XLAB 8. STST $5 DATE $20 TIME $20;
infile datalines dlm=',';
input XLAB STST DATE TIME;
datalines;
1,START,01-JAN-2015,10:15,
1.5,STOP,15-JAN-2015,8:10,
3,START,01-FEB-2015,9:25,
4.5,STOP,15-FEB-2015,10:45,
6,START,01-MAR-2015,8:15,
7.5,STOP,15-MAR-2015,16:15,
9,START,01-APR-2015,21:10,
10.5,STOP,15-APR-2015,10:45,
12, , , ,
;
proc sort; by xlab; run;


proc transpose data=firstrow out=firstrow_;
by xar row;
var title reason char var;
run;

proc transpose data=label out=labelers(rename=(xlab=xlabz _name_=nlabz col1=labvalz));
by xlab;
var stst date time;
run;

proc sort data=immune out=immune_;
   by cycle xval;
run;

data Immune_end;
merge immune_ firstrow_ labelers;
label _NAME_ = ' ';
label nlab = ' ';
if xar='' then xar=0;
run;



proc template;
define statgraph gsv00251;
begingraph / designwidth=7in designheight=4.5in;
entrytitle 'Immunology Profile by Treatment';

	layout lattice / columns=1 rows=4
		rowdatarange=union columndatarange=union
        rowgutter=3px columngutter=3px ;  
			
			blockplot x=xar block=col1 /  class=_name_  datatransparency = .75 display=(values fill outline) filltype=alternate   valuehalign=center
                        				includemissingclass=false valueattrs=GraphDataText;
			

				layout overlay;

					blockplot x=xval block=cycle / datatransparency = .75
												display=(outline fill) 
												filltype=alternate;
					seriesplot x=xval y=yC3 / display=all lineattrs=(pattern=1 thickness=2) 
							                 markerattrs=(symbol=circlefilled size=8 color=red);  
				endlayout;

				layout overlay;

					blockplot x=xval block=cycle / datatransparency = .75
								display=(outline fill) 
								filltype=alternate;
					seriesplot x=xval y=yC4 / display=all lineattrs=(pattern=1 thickness=2) 
							                 markerattrs=(symbol=circlefilled size=8 color=red);    
				endlayout;


			blockplot x=xlabz block=labvalz /  class=nlabz  datatransparency = .75 display=(values fill outline) filltype=alternate   valuehalign=center
                        				includemissingclass=false valueattrs=GraphDataText;



			        rowaxes;
					    rowaxis / griddisplay=on display=(label tickvalues)
            						label=""  labelattrs=(weight=bold) ;
          				rowaxis / griddisplay=on display=(label tickvalues)
            						label="PAR1"  labelattrs=(weight=bold);
          				rowaxis / griddisplay=on display=(label tickvalues) 
            						label="PAR2" labelattrs=(weight=bold);  
						rowaxis / griddisplay=on display=(label tickvalues)
            						label=""  labelattrs=(weight=bold);
        			endrowaxes; 
        			columnaxes;
          				columnaxis / griddisplay=on display=none  OFFSETMin=.003 OFFSETMAX=.003 ;
        			endcolumnaxes;

        entry ' ';
        discretelegend 'a' / title='Patient' across=8;

    endlayout;

    endgraph;
  end;
run;
Contributor
Posts: 25

Re: SAS Graph, Align axis with lattice rows

[ Edited ]

Second problem solved changing all the system of  x values.


The problem of ROWWEIGHT is still there.

 

newcode (only data, template is the same):

data immune;
length cycle $10 xval yC3 yC4 8.;
infile datalines dlm=',';
input cycle $ xval yC3 yC4;
datalines;
Cycle1,0.5,1.080,0.131,
Cycle1,1.5,0.887,0.113,
Cycle2,2,.,.,
Cycle2,2.5,1.180,0.234,
Cycle2,3.5,1.360,0.281,
Cycle3,4,.,.,
Cycle3,4.5,1.000,0.228,
Cycle3,5.5,1.040,0.228,
Cycle4,6,.,.,
Cycle4,6.5,0.789,0.136,
Cycle4,7.5,0.861,0.148,
Cycle4,8,.,.,
;
run;


data firstrow;
length XAR 8. ROW $20 TITLE $20 REASON $50 CHAR $20 VAR $20;
infile datalines dlm=',';
input XAR ROW TITLE REASON CHAR VAR;
datalines;
0.5,ROW 1,ROW 1,FIRST REASON,FIRST ROW,FIRST VAR,
2,ROW 2,ROW 2,SECOND REASON,SECOND ROW,SECOND VAR,
4,ROW 3,ROW 3,THIRD REASON,THIRD ROW,THIRD VAR,
6,ROW 4,ROW 4,FOURTH REASON,FOURTH ROW,FOURTH VAR,
;
proc sort; by xar row; run;
data label;
length XLAB 8. STST $5 DATE $20 TIME $20;
infile datalines dlm=',';
input XLAB STST DATE TIME;
datalines;
0.5,START,01-JAN-2015,10:15,
1.25,STOP,15-JAN-2015,8:10,
2,START,01-FEB-2015,9:25,
3,STOP,15-FEB-2015,10:45,
4,START,01-MAR-2015,8:15,
5,STOP,15-MAR-2015,16:15,
6,START,01-APR-2015,21:10,
7,STOP,15-APR-2015,10:45,
;
proc sort; by xlab; run;

 

Ask a Question
Discussion stats
  • 7 replies
  • 794 views
  • 3 likes
  • 3 in conversation