BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASPhile
Quartz | Level 8

proc format;
value $YN
'Y'='Yes'
'N'='No'
Other='Missing';
run;
dataset has 20 records and one of the variable is smoking.All records for smoing are Blanks.

I applied the format to smoking variable in Proc summary using preloadfmt.

I want to display Missing as 20 . When I run proc summary I see the below counts:

proc summary data = ads1 n completetypes;
by popfl ;
class smoking / preloadfmt ;
var dummy;
output out = want n=count;
format smoking $YN.;
run ;

Missing 0
Yes 0
No 0

Where am I going wrong?

 

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

You need the missing option.

 

When counting with PROC SUMMARY you can use _FREQ_ no need for dummy.

 

proc format;
   value $YN
      'Y'='Yes'
      'N'='No'
      Other='Missing';
   run;
data adsl;
   do id = 1 to 20;
      smoking = ' ';
      output;
      end;
   run;
proc summary data=adsl nway completetypes missing;
   *by popfl;
   class smoking / preloadfmt;
   output out = want;
   format smoking $YN.;
   run;
proc print;
   run;

View solution in original post

2 REPLIES 2
data_null__
Jade | Level 19

You need the missing option.

 

When counting with PROC SUMMARY you can use _FREQ_ no need for dummy.

 

proc format;
   value $YN
      'Y'='Yes'
      'N'='No'
      Other='Missing';
   run;
data adsl;
   do id = 1 to 20;
      smoking = ' ';
      output;
      end;
   run;
proc summary data=adsl nway completetypes missing;
   *by popfl;
   class smoking / preloadfmt;
   output out = want;
   format smoking $YN.;
   run;
proc print;
   run;
data_null__
Jade | Level 19

You might want to only show the missing row when there are missing values.  Here is one way to accomplish that by recoding blank SMOKING to "Missing"

 

data adsl;
   length smoking $8;
   do id = 1 to 20;
      smoking = chooseC(rantbl(4,.5,.5,.1),'Y','N','Missing');
      output;
      end;
   run;
proc print;
   run;
proc format;
   value $YN(notsorted default=8) 
      'Y'='Yes'
      'N'='No'
      ;
   quit;
proc summary data=adsl nway completetypes missing;
   class smoking / preloadfmt order=data;
   output out=want / levels;
   format smoking $YN.;
   run;
proc print;
   run;

 

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!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1469 views
  • 0 likes
  • 2 in conversation