DATA Step, Macro, Functions and more

Proc means data set creation?

Reply
Contributor
Posts: 39

Proc means data set creation?

/*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*/

 

Super User
Posts: 23,291

Re: Proc means data set creation?

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.

Super User
Posts: 13,321

Re: Proc means data set creation?

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; 
Contributor
Posts: 39

Re: Proc means data set creation?

/*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_nameMinMaxMean
Age197238
Balance_due$5,009$10,001$7,053

 

*/

/*Appreciate your help.

Mirisa*/

 

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