BookmarkSubscribeRSS Feed
BLawrence
Fluorite | Level 6

In v9.4, I am using PROC MEANS to compute the mean of a numeric variable using a CLASS statement. The class variable is a two-digit numeric variable formatted as z2. - i.e., with a leading zero for single-digit values. It seems that SAS both objects to the format and ignores it. In the printed output, it replaces all two-digit values with asterisks, and it prints single-digit values without the leading zero. The only way I can find to make it print values instead of asterisks is to strip the variable of its format - but I really want the leading zero. The log shows no error statement of any sort.

9 REPLIES 9
Reeza
Super User

Can you post an image and ideally code to replicate your issue. Use SASHELP.CLASS to start with if that helps. 

Tom
Super User Tom
Super User

I would report this to SAS as a bug. To work around it convert your class variable to character.

data class;
 set sashelp.class ;
 x = age-5 ;
 format x z2.;
 y=put(x,z2.);
run;

proc means data=class ;
 class x;
 var height;
run;

proc means data=class ;
 class y;
 var height;
run;
BLawrence
Fluorite | Level 6

When I work with this dataset for my own purposes, I always define that variable as character - I strongly prefer it that way. Unfortunately, my client disagrees!

BLawrence
Fluorite | Level 6

I took Tom's advice and reported this problem to SAS. The problem was acknowledged and is described in this SAS note:

http://support.sas.com/kb/51/403.html

 

Thanks to all who responded here.

Tom
Super User Tom
Super User

So another work around is to make a user defined format with a longer default length.

proc format;
  value myz (default=4) other = [Z2.] ;
run;

data class;
 set sashelp.class ;
 x = age-5 ;
 format x myz2.;
 y=put(x,z2.);
run;

proc means data=class ;
 class x;
 var height;
run;
Kurt_Bremser
Super User

I tried it with SAS 9.2, same effect.

When using by instead of class, the class/by variable is printed correctly (but the layout of the report is different, of course).

 

Report to SAS TS as a probable bug.

aknight
SAS Employee

PROC SUMMARY works well with formatted values....

 

data temp;

set sashelp.cars;

format region z2.;

if origin='Asia' then region=1;

else if origin='Europe' then region=2;

else if origin='USA' then region=3;

run;

proc summary data=temp nway;

class make region;

output out=temp1;

run;

proc print data=temp1;run;

 

 

The SAS System

 

Obs Make region _TYPE_ _FREQ_
1 Acura 01 3 7
2 Audi 02 3 19
3 BMW 02 3 20
4 Buick 03 3 9
5 Cadillac 03 3 8
6 Chevrolet 03 3 27
7 Chrysler 03 3 15
8 Dodge 03 3 13
9 Ford 03 3 23
10 GMC 03 3 8
11 Honda 01 3 17
12 Hummer 03 3 1
13 Hyundai 01 3 12
14 Infiniti 01 3 8
15 Isuzu 01 3 2
16 Jaguar 02 3 12
17 Jeep 03 3 3
18 Kia 01 3 11
19 Land Rover 02 3 3
20 Lexus 01 3 11
21 Lincoln 03 3 9
22 MINI 02 3 2
23 Mazda 01 3 11
24 Mercedes-Benz 02 3 26
25 Mercury 03 3 9
26 Mitsubishi 01 3 13
27 Nissan 01 3 17
28 Oldsmobile 03 3 3
29 Pontiac 03 3 11
30 Porsche 02 3 7
31 Saab 02 3 7
32 Saturn 03 3 8
33 Scion 01 3 2
34 Subaru 01 3 11
35 Suzuki 01 3 8
36 Toyota 01 3 28
37 Volkswagen 02 3 15
38 Volvo 02 3 12

 

Kurt_Bremser
Super User

@aknight:

When you produce output, you get the same effect:

data temp;
set sashelp.cars;
format region z2.;
if origin='Asia' then region=1;
else if origin='Europe' then region=2;
else if origin='USA' then region=11;
run;

proc summary data=temp nway print;
class make region;
output out=temp1;
run;

Output (excerpt):

    The SUMMARY Procedure

                             N
Make             region    Obs
------------------------------
Acura                 1      7

Audi                  2     19

BMW                   2     20

Buick                 *      9

Cadillac              *      8

Chevrolet             *     27

Chrysler              *     15

Dodge                 *     13

Ford                  *     23

GMC                   *      8

Honda                 1     17

Hummer                *      1

Hyundai               1     12

Infiniti              1      8

Isuzu                 1      2

Jaguar                2     12

Jeep                  *      3

The output stays that way even when you add another

format region z2.;

in the SUMMARY procedure.

ballardw
Super User

Maybe another report procedure like Proc tabulate? You can get most of the same statistics and have advantages of style overrides making prettier tables than Means.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 9 replies
  • 1733 views
  • 5 likes
  • 6 in conversation