BookmarkSubscribeRSS Feed
dunga
Obsidian | Level 7

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

 

3 REPLIES 3
Reeza
Super User

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.

ballardw
Super User

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; 
dunga
Obsidian | Level 7

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

 

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!

How to Concatenate Values

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.

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
  • 766 views
  • 1 like
  • 3 in conversation