BookmarkSubscribeRSS Feed
hnam
Calcite | Level 5

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;

3 REPLIES 3
Astounding
PROC Star

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.

FloydNevseta
Pyrite | Level 9

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=_:) 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;

Ksharp
Super User

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1284 views
  • 1 like
  • 4 in conversation