Date: Wed, 27 Apr 2005 11:42:13 -0700
Reply-To: Jack Hamilton <jfh@STANFORDALUMNI.ORG>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jack Hamilton <jfh@STANFORDALUMNI.ORG>
Subject: Re: display numeric vars with decimals
In-Reply-To: <200504271106450890.004D4EB5@mailserver.algx.net>
Content-Type: text/plain; charset="us-ascii"
Ling Yun Chen wrote:
> Hi Jim, you are right, however, my criterion is more
> complicated than that.
> I have a third variable C that determines whether the values
> of A should
> be displayed as 2 decimals, 1 decimal, or as integers.
It would have been helpful if you had mentioned this key piece of
information in your first message.
> So I
> cannot break
> up the values of A like you suggested in your proc format
> statement. For
> example, if C=1, then whatever value A has, it needs to be
> displayed as 1
> decimal, if C=2, then the values of A should be displayed as
> 2 decimals.
> Any ideas? Thanks!
=====
data test (keep=decimals value displayed);
do i = 1 to 5;
do decimals = 0 to 3;
value = ranuni(95605) * 10;
displayed = value;
output;
end;
end;
stop;
run;
proc report data=test nowindows missing nocenter;
columns value decimals displayed;
define _all_ / display;
compute displayed;
call define(_col_, 'format', '10.' || put(decimals, z1.0));
endcomp;
run;
=====
prints:
=====
The SAS System 11:23
Wednesday, April 27, 2005 5
value decimals displayed
3.4648784 0 3
3.3165982 1 3.3
2.0278367 2 2.03
8.0749122 3 8.075
8.1445687 0 8
7.6102304 1 7.6
5.2384895 2 5.24
3.8716015 3 3.872
5.5787562 0 6
0.951658 1 1.0
9.5194012 2 9.52
6.4120504 3 6.412
7.6308912 0 8
1.8146458 1 1.8
2.6590652 2 2.66
2.289426 3 2.289
0.5009372 0 1
7.2236493 1 7.2
6.0467117 2 6.05
2.5131059 3 2.513
=====
Where "displayed" is "value" printed with "decimals" decimal points.