Data visualization with SAS programming

I have been working on reproducing a graph with 3 variables and ingraph labelling

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

I have been working on reproducing a graph with 3 variables and ingraph labelling

I have been trying to reproduce the attached graph using the following data but I have not been able to find an example that fits it perfectly. I need help urgently I have been on it for over a week and am at my wits end.

 


data NAR;
input Drug$ Time Meanlog_NAR @@;
cards;
Placebo 0 .73
Placebo 1 .57
Placebo 2 0.56
Placebo 3 0.54
Placebo 4 0.52
Placebo 5 0.54
Placebo 6 0.56
Placebo 7 0.57
Placebo 8 0.52
Tripolidine 0 0.62
Tripolidine 1 0.57
Tripolidine 2 0.59
Tripolidine 3 0.54
Tripolidine 4 0.59
Tripolidine 5 0.58
Tripolidine 6 0.62
Tripolidine 7 0.57
Tripolidine 8 0.58
pseudoephedrine 0 0.68
pseudoephedrine 1 0.44
pseudoephedrine 2 0.40
pseudoephedrine 3 0.41
pseudoephedrine 4 0.34
pseudoephedrine 5 0.37
pseudoephedrine 6 0.37
pseudoephedrine 7 0.33
pseudoephedrine 8 0.36
Tripo_pseudo 0 0.68
Tripo_pseudo 1 0.50
Tripo_pseudo 2 0.47
Tripo_pseudo 3 0.45
Tripo_pseudo 4 0.44
Tripo_pseudo 5 0.46
Tripo_pseudo 6 0.43
Tripo_pseudo 7 0.42
Tripo_pseudo 8 0.45
;
run;

proc sgplot data=NAR;
title 'Separate Fit by Sex';
styleattrs datasymbols=(circlefilled squarefilled diamondfilled trianglefilled)
datalinepatterns=(solid);
lineparm y=Meanlog_NAR x=Time /Group=Drug lineattrs=(thickness=2)
nomissinggroup;
xaxis min=10;
run;

 

 


Accepted Solutions
Solution
‎09-04-2017 02:33 PM
Frequent Contributor
Posts: 83

Re: I have been working on reproducing a graph with 3 variables and ingraph labelling

The longest drug name in your data set is 15 characters long, so I added a length statement to the data step.  A SERIES plot with REFLINEs gets pretty close to the graphic you asked for.  

 

I'm using SAS University Edition.  I couldn't get the subscript 2 to display properly in the y axis label.  There's no option on the KEYLEGEND statement to split the really long drug name.  You might be able to do that if you use annotation instead.  

 

 

data NAR;
  length drug $ 15;
  input Drug $ Time Meanlog_NAR;
  cards;
Placebo 0 .73
Placebo 1 .57
Placebo 2 0.56
Placebo 3 0.54
Placebo 4 0.52
Placebo 5 0.54
Placebo 6 0.56
Placebo 7 0.57
Placebo 8 0.52
Tripolidine 0 0.62
Tripolidine 1 0.57
Tripolidine 2 0.59
Tripolidine 3 0.54
Tripolidine 4 0.59
Tripolidine 5 0.58
Tripolidine 6 0.62
Tripolidine 7 0.57
Tripolidine 8 0.58
pseudoephedrine 0 0.68
pseudoephedrine 1 0.44
pseudoephedrine 2 0.40
pseudoephedrine 3 0.41
pseudoephedrine 4 0.34
pseudoephedrine 5 0.37
pseudoephedrine 6 0.37
pseudoephedrine 7 0.33
pseudoephedrine 8 0.36
Tripo_pseudo 0 0.68
Tripo_pseudo 1 0.50
Tripo_pseudo 2 0.47
Tripo_pseudo 3 0.45
Tripo_pseudo 4 0.44
Tripo_pseudo 5 0.46
Tripo_pseudo 6 0.43
Tripo_pseudo 7 0.42
Tripo_pseudo 8 0.45
;
run;

proc format;
  value $drugtype  
            'Placebo'='Placebo                             '
        'Tripolidine'='Tripolidine HCL                     '
    'pseudoephedrine'='Pseudoephedrine HCL                 '
       'Tripo_pseudo'='Tripolidine HCL+ Pseudoephedrine HCL'
      ;
run;

ods graphics / attrpriority=none width=8in noborder;

ods escapechar='^';

ODS RTF FILE='/folders/myfolders/ODS Graphics/drug plot.rtf';

proc sgplot data=NAR noborder nowall;
  title 'Separate Fit by Sex';
  styleattrs datasymbols=(diamondfilled squarefilled trianglefilled circlefilled)
    datalinepatterns=(solid);
  refline 0 3 6 / axis=x 
                  label=('First Dose' 'Second Dose' 'Third Dose') 
                  splitchar=' '
                  lineattrs=(pattern=shortdash);
  series x=time y=meanlog_NAR / group=drug lineattrs=(thickness=2) nomissinggroup markers;
  format drug $drugtype. ;
  xaxis type=discrete label="Time (hours)";
  yaxis min=0.2 max=0.8 label="Mean Log NAR (cm H ^{unicode '2082'x} O / L / sec)";
  keylegend / title='' position=right noborder;
run;

ODS RTF CLOSE;

SERIES plot by type of drugSERIES plot by type of drug

View solution in original post


All Replies
Occasional Contributor
Posts: 9

I need help reproducing a graph with 3 variables and ingraph labelling

I have been trying to reproduce the attached graph using the following data but I have not been able to find an example that fits it perfectly. I need help urgently I have been on it for over a week and am at my wits end.

 


data NAR;
input Drug$ Time Meanlog_NAR @@;
cards;
Placebo 0 .73
Placebo 1 .57
Placebo 2 0.56
Placebo 3 0.54
Placebo 4 0.52
Placebo 5 0.54
Placebo 6 0.56
Placebo 7 0.57
Placebo 8 0.52
Tripolidine 0 0.62
Tripolidine 1 0.57
Tripolidine 2 0.59
Tripolidine 3 0.54
Tripolidine 4 0.59
Tripolidine 5 0.58
Tripolidine 6 0.62
Tripolidine 7 0.57
Tripolidine 8 0.58
pseudoephedrine 0 0.68
pseudoephedrine 1 0.44
pseudoephedrine 2 0.40
pseudoephedrine 3 0.41
pseudoephedrine 4 0.34
pseudoephedrine 5 0.37
pseudoephedrine 6 0.37
pseudoephedrine 7 0.33
pseudoephedrine 8 0.36
Tripo_pseudo 0 0.68
Tripo_pseudo 1 0.50
Tripo_pseudo 2 0.47
Tripo_pseudo 3 0.45
Tripo_pseudo 4 0.44
Tripo_pseudo 5 0.46
Tripo_pseudo 6 0.43
Tripo_pseudo 7 0.42
Tripo_pseudo 8 0.45
;
run;

proc sgplot data=NAR;
title 'Separate Fit by Sex';
styleattrs datasymbols=(circlefilled squarefilled diamondfilled trianglefilled)
datalinepatterns=(solid);
lineparm y=Meanlog_NAR x=Time /Group=Drug lineattrs=(thickness=2)
nomissinggroup;
xaxis min=10;
run;

 

 

Super User
Posts: 19,058

Re: I need help reproducing a graph with 3 variables and ingraph labelling

There are two graphs. Which did you want? 

 

Use a series statement to get the lines

Use scatter statement to get the points. 

Use REF to get the reference lines. 

Respected Advisor
Posts: 4,811

Re: I need help reproducing a graph with 3 variables and ingraph labelling

[ Edited ]

Here is @SuzanneDorinski's code again with newer options  and ODS statements commented out. Try it again

 

data NAR;

length drug $ 15;

input Drug $ Time Meanlog_NAR;

cards;

Placebo 0 .73

Placebo 1 .57

Placebo 2 0.56

Placebo 3 0.54

Placebo 4 0.52

Placebo 5 0.54

Placebo 6 0.56

Placebo 7 0.57

Placebo 8 0.52

Tripolidine 0 0.62

Tripolidine 1 0.57

Tripolidine 2 0.59

Tripolidine 3 0.54

Tripolidine 4 0.59

Tripolidine 5 0.58

Tripolidine 6 0.62

Tripolidine 7 0.57

Tripolidine 8 0.58

pseudoephedrine 0 0.68

pseudoephedrine 1 0.44

pseudoephedrine 2 0.40

pseudoephedrine 3 0.41

pseudoephedrine 4 0.34

pseudoephedrine 5 0.37

pseudoephedrine 6 0.37

pseudoephedrine 7 0.33

pseudoephedrine 8 0.36

Tripo_pseudo 0 0.68

Tripo_pseudo 1 0.50

Tripo_pseudo 2 0.47

Tripo_pseudo 3 0.45

Tripo_pseudo 4 0.44

Tripo_pseudo 5 0.46

Tripo_pseudo 6 0.43

Tripo_pseudo 7 0.42

Tripo_pseudo 8 0.45

;

run;

proc format;

value $drugtype

'Placebo'='Placebo '

'Tripolidine'='Tripolidine HCL '

'pseudoephedrine'='Pseudoephedrine HCL '

'Tripo_pseudo'='Tripolidine HCL+ Pseudoephedrine HCL'

;

run;

ods graphics / /*attrpriority=none*/ width=8in noborder;

ods escapechar='^';

*ODS RTF FILE='/folders/myfolders/ODS Graphics/drug plot.rtf';

data map;

id="one"; linepattern = "solid";

value ='Placebo '; markersymbol="diamondfilled "; output;

value ='Tripolidine HCL '; markersymbol="squarefilled "; output;

value ='Pseudoephedrine HCL '; markersymbol="trianglefilled"; output;

value ='Tripolidine HCL+ Pseudoephedrine HCL'; markersymbol="circlefilled "; output;

run;

proc sgplot data=NAR noborder dattrmap=map /*nowall*/;

title;

*styleattrs datasymbols=(diamondfilled squarefilled trianglefilled circlefilled)

datalinepatterns=(solid);

refline 0 3 6 / axis=x

label=('First Dose' 'Second Dose' 'Third Dose')

splitchar=' '

lineattrs=(pattern=shortdash);

series x=time y=meanlog_NAR / group=drug lineattrs=(thickness=2)

nomissinggroup markers markerattrs=(size=10) attrid=one;

format drug $drugtype. ;

xaxis type=discrete label="Time (hours)";

yaxis min=0.2 max=0.8 label="Mean Log NAR (cm H ^{unicode '2082'x} O / L / sec)";

keylegend / title='' position=right noborder;

run;

*ODS RTF CLOSE;

 

PG
Solution
‎09-04-2017 02:33 PM
Frequent Contributor
Posts: 83

Re: I have been working on reproducing a graph with 3 variables and ingraph labelling

The longest drug name in your data set is 15 characters long, so I added a length statement to the data step.  A SERIES plot with REFLINEs gets pretty close to the graphic you asked for.  

 

I'm using SAS University Edition.  I couldn't get the subscript 2 to display properly in the y axis label.  There's no option on the KEYLEGEND statement to split the really long drug name.  You might be able to do that if you use annotation instead.  

 

 

data NAR;
  length drug $ 15;
  input Drug $ Time Meanlog_NAR;
  cards;
Placebo 0 .73
Placebo 1 .57
Placebo 2 0.56
Placebo 3 0.54
Placebo 4 0.52
Placebo 5 0.54
Placebo 6 0.56
Placebo 7 0.57
Placebo 8 0.52
Tripolidine 0 0.62
Tripolidine 1 0.57
Tripolidine 2 0.59
Tripolidine 3 0.54
Tripolidine 4 0.59
Tripolidine 5 0.58
Tripolidine 6 0.62
Tripolidine 7 0.57
Tripolidine 8 0.58
pseudoephedrine 0 0.68
pseudoephedrine 1 0.44
pseudoephedrine 2 0.40
pseudoephedrine 3 0.41
pseudoephedrine 4 0.34
pseudoephedrine 5 0.37
pseudoephedrine 6 0.37
pseudoephedrine 7 0.33
pseudoephedrine 8 0.36
Tripo_pseudo 0 0.68
Tripo_pseudo 1 0.50
Tripo_pseudo 2 0.47
Tripo_pseudo 3 0.45
Tripo_pseudo 4 0.44
Tripo_pseudo 5 0.46
Tripo_pseudo 6 0.43
Tripo_pseudo 7 0.42
Tripo_pseudo 8 0.45
;
run;

proc format;
  value $drugtype  
            'Placebo'='Placebo                             '
        'Tripolidine'='Tripolidine HCL                     '
    'pseudoephedrine'='Pseudoephedrine HCL                 '
       'Tripo_pseudo'='Tripolidine HCL+ Pseudoephedrine HCL'
      ;
run;

ods graphics / attrpriority=none width=8in noborder;

ods escapechar='^';

ODS RTF FILE='/folders/myfolders/ODS Graphics/drug plot.rtf';

proc sgplot data=NAR noborder nowall;
  title 'Separate Fit by Sex';
  styleattrs datasymbols=(diamondfilled squarefilled trianglefilled circlefilled)
    datalinepatterns=(solid);
  refline 0 3 6 / axis=x 
                  label=('First Dose' 'Second Dose' 'Third Dose') 
                  splitchar=' '
                  lineattrs=(pattern=shortdash);
  series x=time y=meanlog_NAR / group=drug lineattrs=(thickness=2) nomissinggroup markers;
  format drug $drugtype. ;
  xaxis type=discrete label="Time (hours)";
  yaxis min=0.2 max=0.8 label="Mean Log NAR (cm H ^{unicode '2082'x} O / L / sec)";
  keylegend / title='' position=right noborder;
run;

ODS RTF CLOSE;

SERIES plot by type of drugSERIES plot by type of drug

Occasional Contributor
Posts: 9

Re: I have been working on reproducing a graph with 3 variables and ingraph labelling

Hello Suzanne,

Thank you so much for your prompt response. I noticed the code is giving
error messages. I pasted the message for you to take a look.
Thank you for taking the time to answer my question.

Warm regards,
Uche.


125 ods graphics / attrpriority=none width=8in noborder;
------------
22
202
ERROR 22-322: Syntax error, expecting one of the following: ;, ANTIALIAS,
ANTIALIASMAX, BORDER,
BYLINE, DISCRETEMAX, GROUPMAX, HEIGHT, IMAGEMAP, IMAGENAME,
LABELMAX, MAXLEGENDAREA,
NOANTIALIAS, NOBORDER, NOIMAGEMAP, NOSCALE, NOSCALEMARKERS,
OUTPUTFMT, PANELCELLMAX,
RESET, SCALE, SCALEMARKERS, TIPMAX, WIDTH.
ERROR 202-322: The option or parameter is not recognized and will be
ignored.
126
127 ods escapechar='^';
128
129 ODS RTF FILE='/folders/myfolders/ODS Graphics/drug plot.rtf';
ERROR: Physical file does not exist, C:\folders\myfolders\ODS Graphics\drug
plot.rtf.
ERROR: Fatal ODS error has occurred. Unable to continue processing this
output destination.
WARNING: No body file. RTF output will not be created.
130
131 proc sgplot data=NAR noborder nowall;
--------
22
202
ERROR 22-322: Syntax error, expecting one of the following: ;, (,
CYCLEATTRS, DATA, DATTRMAP,
DESCRIPTION, NOAUTOLEGEND, NOCYCLEATTRS, PAD, SGANNO,
TMPLOUT, UNIFORM.
ERROR 202-322: The option or parameter is not recognized and will be
ignored.
132 title 'Separate Fit by Sex';
133 styleattrs datasymbols=(diamondfilled squarefilled trianglefilled
circlefilled)
----------
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
134 datalinepatterns=(solid);
135 refline 0 3 6 / axis=x
136 label=('First Dose' 'Second Dose' 'Third Dose')
137 splitchar=' '
---------
22
76
ERROR 22-322: Syntax error, expecting one of the following: ;, AXIS,
DISCRETEOFFSET, LABEL, LABELLOC,
LABELPOS, LEGENDLABEL, LINEATTRS, NAME, NOCLIP, TRANSPARENCY.
ERROR 76-322: Syntax error, statement will be ignored.
138 lineattrs=(pattern=shortdash);
139 series x=time y=meanlog_NAR / group=drug lineattrs=(thickness=2)
nomissinggroup markers;
140 format drug $drugtype. ;
141 xaxis type=discrete label="Time (hours)";
142 yaxis min=0.2 max=0.8 label="Mean Log NAR (cm H ^{unicode '2082'x} O
/ L / sec)";
143 keylegend / title='' position=right noborder;
144 run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SGPLOT used (Total process time):
real time 0.04 seconds
cpu time 0.03 seconds

145
146 ODS RTF CLOSE;

147
148 proc sgplot data=NAR noborder nowall;
--------
22
202
ERROR 22-322: Syntax error, expecting one of the following: ;, (,
CYCLEATTRS, DATA, DATTRMAP,
DESCRIPTION, NOAUTOLEGEND, NOCYCLEATTRS, PAD, SGANNO,
TMPLOUT, UNIFORM.
ERROR 202-322: The option or parameter is not recognized and will be
ignored.
149 title 'Separate Fit by Sex';
150 styleattrs datasymbols=(diamondfilled squarefilled trianglefilled
circlefilled)
----------
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
151 datalinepatterns=(solid);
152 refline 0 3 6 / axis=x
153 label=('First Dose' 'Second Dose' 'Third Dose')
154 splitchar=' '
---------
22
76
ERROR 22-322: Syntax error, expecting one of the following: ;, AXIS,
DISCRETEOFFSET, LABEL, LABELLOC,
LABELPOS, LEGENDLABEL, LINEATTRS, NAME, NOCLIP, TRANSPARENCY.
ERROR 76-322: Syntax error, statement will be ignored.
155 lineattrs=(pattern=shortdash);
156 series x=time y=meanlog_NAR / group=drug lineattrs=(thickness=2)
nomissinggroup markers;
157 format drug $drugtype. ;
158 xaxis type=discrete label="Time (hours)";
159 yaxis min=0.2 max=0.8 label="Mean Log NAR (cm H ^{unicode '2082'x} O
/ L / sec)";
160 keylegend / title='' position=right noborder;
161 run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SGPLOT used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds

Super User
Posts: 19,058

Re: I have been working on reproducing a graph with 3 variables and ingraph labelling

You need to update the code - at minimum at least the path where she's saving the file.

 

The location of the error makes me suspect that you may have an error before this procedure, not with the actual code. 

What version of SAS do you have and what interface are you working with, ie SAS Studio, Base SAS, SAS EG?

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 263 views
  • 1 like
  • 4 in conversation