Date: Mon, 25 Jun 2007 23:31:23 -0700
Reply-To: Joep Steeman <jsteeman@BUSINESSDECISION.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joep Steeman <jsteeman@BUSINESSDECISION.COM>
Organization: http://groups.google.com
Subject: Re: if then format
In-Reply-To: <1182803231.886975.213430@q75g2000hsh.googlegroups.com>
Content-Type: text/plain; charset="us-ascii"
On 25 jun, 22:27, Captain <apsteinb...@hotmail.com> wrote:
> Hi,
>
> I have a variable that has numbers in it, but based on another
> variable that value could be a percent or whole number. So in other
> words I have a variable called value_results.
>
> Value_results Current_time First_time
> Group_A 12.5 33
> Group_B 12.5 33
> Group_C 25 33
> TOTAL_Group_A .25 .33
> TOTAL_Group_B .25 .33
> TOTAL_Group_C .50 .33
>
> I want the values for the group_a - group_c to stay whole number and I
> want to format the values for group_a_total - group_c_total to be
> Percentages. I tried this code, but it is not formating the
> variables right. The current_time gets formated correctly, but
> first_time does not.
>
> proc format;
> picture perc
> 0-100 = "009.0%" (mult = 1000);
> run;
>
> data testb;
> set testa;
> if upcase(value_results) =:'TOTAL_' then do;
> format Current_time First_time perc.;
> end;
> run;
>
> I have looked for help, but can not find anything. Thanks
You might make use of conditonal formatting. Is this to your liking?
data have;
length value_results $ 20 result 4;
input value_results result 6.2;
cards;
Group_A 12.5
Group_B 12.5
Group_C 25.0
TOTAL_Group_A 0.25
TOTAL_Group_B 0.25
TOTAL_Group_C 0.50
;
run;
proc format;
value $total 'TOTAL' = 'pctfmt'
other = 'numfmt';
value pctfmt low-high = [percent.]; /* square brackets = existing
format */
value numfmt low-high = [4.2];
run;
data want;
set have;
length result_formatted $ 10;
used_fmt = put(substr(value_results, 1, 5), $total.);
result_formatted = putn(result, used_fmt); /* putn function */
put (_all_) (=);
run;
Regards, Joep
|