Help using Base SAS procedures

Proc Means and sgplot

Reply
Occasional Contributor
Posts: 7

Proc Means and sgplot

Hi All

I am trying to plot the mean of ser creatinine levels (64 obs) against different time points. I calculated the mean and then plotted it (the code may be lenghty). But on the x-axis the graph is generating in the order day15 day180 day3  day30 day360 day7 day720 day90 instead of day 3 through day720.  Could someone please take a look and help me resolve this:

Thanks in advance.

Hari

proc means data=tab4b mean;
var day3 day7 day15 day30 day90 day180 day360 day720;
output out=tab4c;
run;

data tab4c;
set c(firstobs=4 obs=4);
drop _type_ _freq_ _stat_;
/*avg=mean(day3, day7, day15);*/
run;

proc transpose data=c out= tab4d;
run;
data tab4e;
set tab4d(firstobs=3 obs=10);
keep day col4;
label col4=mean;
day=put(_name_, 8.);
run;

proc gplot data=tab4e;
plot col4*day;
symbol value=circle color=red interpol=spline;
run;
quit;

Super User
Posts: 5,099

Proc Means and sgplot

hnam,

What you are noticing is that the fields are in alphabetical order.  While you could conceivably change your variable names in TAB4B, it's just as easy to use this variation.  Add to your OUTPUT statement within PROC MEANS:

mean = day003 day007 day015 day030 day090 day180 day360 day720

That will change the variable names in TAB4C, without having to change TAB4B.  Also, notice how the word MEAN on the PROC statement is affecting the printed report, but does not affect the output data set TAB4C.

If you use this change that I'm recommending, you may have to change your subsequent program.  For example, there will only be one observation in TAB4C, so when you transpose you will end up using COL1 instead of COL4.  But it's worth the effort to familiarize yourself with the structure of output data sets from PROC MEANS.

Good luck.

Frequent Contributor
Posts: 101

Proc Means and sgplot

Let's simplify things a little. The problem is the day variable is plotting alphabetically instead of the order of the series. Run this instead.

* just output the mean only and drop vars that begin with _;

proc summary data=tab4b;
var day3 day7 day15 day30 day90 day180 day360 day720;
output out=tab4c (drop=_Smiley Happy mean=;
run;

* rename transposed vars to something meaningful;

proc transpose data=tab4c out=tab4d (rename=(_name_=day col1=mean));
run;

* change the day value - for example, day3 to day003;

data tab4e;
set tab4d;
length _n 8;
_n = substr( day, 4 );
day = cats( 'day', put( _n, z3. ));
drop _:;
run;

proc gplot data=tab4e;

plot mean*day;

symbol value=circle color=red interpol=spline;

run;

quit;

Super User
Posts: 9,691

Proc Means and sgplot

As Astounding said. SAS order the value based on alphabetical order.

You can customize the order by adding a blank before the value to cheat SAS.

Because a blank is before than all of other alpha character.

Like:

..............

proc transpose data=c out= tab4d;

run;

data tab4d;

set tab4d;

length col $ 50 ; *make the variate long enough to hold the adding blanks;

select(col);

when('day3')   col='                       day3'; *day3 is the first value so need the most blanks;

when('day7')   col='                   day7';

.........................

Ksharp

Ask a Question
Discussion stats
  • 3 replies
  • 218 views
  • 1 like
  • 4 in conversation