Hello
Why in the following code the output of frequency in "name" field is not correct.
It shows that there are no missing values for field "name " but actually there are 4 missing value
proc format ;
value $missfmt
''="missing"
other="Non Missing";
value missfmt
.="missing"
other="Non Missing";
run;
data have;
set sashelp.class;
if _N_ in (2,5,8,13) then do;
call missing(of _numeric_);
end;
if _N_ in (5,6,8,12) then do;
call missing(of _character_);
end;
run;
proc freq data=have;
format _character_ $missfmt.;
tables _character_/missing missprint nocum nopercent;
format _numeric_ missfmt.;
tables _numeric_/missing missprint nocum nopercent;
run;
This is the case for both Sex and Name (the character variables) because you have to specify your format with a blank " " in the Format Procedure and not a "". So this gives your the desired result
proc format ;
value $missfmt
' '="missing"
other="Non Missing";
value missfmt
.="missing"
other="Non Missing";
run;
the reason is because the name field for record 5 has a space. so it is not null nor is it blank for the name field.
try this code and do a proc
proc format ;
value $missfmt
''="missing"
other="Non Missing";
value missfmt
.="missing"
other="Non Missing";
run;
data have;
set sashelp.class;
if _N_ in (2,5,8,13) then do;
call missing(of _numeric_);
end;
if _N_ in (5,6,8,12) then do;
call missing(of _character_);
end;
if substr(name,1,1)=" " then notblank = 1;
run;
proc freq data=have ;
format _character_ $missfmt.;
tables _character_/missing missprint nocum nopercent;
format _numeric_ missfmt.;
tables _numeric_/missing missprint nocum nopercent;
run;
proc freq data=have;
tables notblank / missing;
quit;
freq on the new variable notblank in the dataset have
notblank | Frequency |
---|---|
missing | 15 |
Non Missing | 4 |
notblank | Frequency | Percent | Cumulative Frequency |
Cumulative Percent |
---|---|---|---|---|
. | 15 | 78.95 | 15 | 78.95 |
1 | 4 | 21.05 | 19 | 100.00 |
Use the FMTLIST option to PROC FORMAT to see what format you defined.
Because you did not include anything inside the quotes in your Value statement you ended up with a format for a string that consists of a single quote character instead of one for a blank string.
value $missfmt
' '='missing'
other="Non Missing"
;
@Tom meant
Use the FMTLIB option to PROC FORMAT to see what format you defined.
not
Use the FMTLIST option to PROC FORMAT to see what format you defined.
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 25. 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.