/*Hi SAS Forum,
Could you please help me on this.
I have the below dataset which shows the age and outstanding balance of 3 customers*/
data have_1;
input acct_num age balance_due;
cards;
111 72 5009
222 24 10001
333 19 6150
;
run;
/*Q: I want to generate a SAS dataset ("a SAS data set" is emphazised again) like
below where values for "Min", "Max" and "Mean" fields, all should have rounded values without any decimals.
And when the field called Variable_name gets a value of balance_due, then the values for fields called
Min, Max and Mean should get a $ sign prefixed with '000 separator.
*/
/*Answer*/
/*
Variable_name Min Max Mean
age 19 72 38
balance_due $5,009 $10,001 $7,053
*/
/*I attmepted below code but it generates below SAS dataset which is not acceptable cos age cannot get $ values.*/
/*
variable_Name MIN MAX MEAN
age $19 $72 $38
balance_due $5,009 $10,001 $7,053
*/
/*Below is my code*/
proc means data=have_1 min max mean maxdec=0;
var
age
balance_due
;
output out=have_2;
run;
/*Preparing for transposing the proc means output*/
data have_3;
set have_2;
if _stat_ in ('N' 'STD') then delete;
drop _type_ _freq_ ;
run;
/*transposing the proc means output*/
proc transpose data=have_3 out=rotated_dataset name=variable_Name;
id _stat_;
run;
/*Formatting only values in balance_due variables to dollars */
data want;
set rotated_dataset;
/*Formatting only values in balance_due variables to dollars */
if variable_Name ='balance_due' then do;
format min max mean dollar12.;
end;
run;
/*Mirisa*/
Formats are not conditional in SAS. A column can have only one format.
However, I suggest you look at PROC TABULATE instead, you'll have more options to customize your stats and the formats. If you want a data set then that's not a good option though.
You should also look at the STACKODS option in PROC MEANS.
And the MAXDEC=0 option.
It really does help to show EXACTLY what you want the output to look like.
And which part is a dataset and which part is other output;
I am not sure what the names of the output variables should be, what types.
And as @Reeza pointed out, a single variable may only have a single format associated
The maxdec option does not relate to statistics in an output dataset, only to displayed output.
Maybe this will give you an idea:
proc means data=have_1 ; var age balance_due ; output out=have2 (drop= _:) min= max= mean= / autoname; run;
/*Thanks.
Hi ballardw,
Sorry, my posting was not clear.
I am making it clearer now.*/
/*I have this dataset. It shows the age and outstanding balance of 3 customers.*/
data have_1;
input acct_num age balance_due;
cards;
111 72 5009
222 24 10001
333 19 6150
;
run;
/*Question:
I want to generate a SAS dataset ("a SAS data set" and not displayed output) exactly like below*/
/*Answer*/
/*
Variable_name | Min | Max | Mean |
Age | 19 | 72 | 38 |
Balance_due | $5,009 | $10,001 | $7,053 |
*/
/*Appreciate your help.
Mirisa*/
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: