Hi,
I would like to know if there is a way to get something similar to the _TYPE_ variable in proc means output to identify the levels when using ODS OUTPUT instead of OUTPUT OUT=.
When having missing values in the variable listed in the class statement, there is no direct way to distinguish level 0 from level 1.
A workaround is to change the missing value to something else before proc means.
Here is some code to illustrate the issue:
data class;
set sashelp.class end=eof;
output;
if eof then
do;
sex=' ';
age=.;
output;
end;
run;
proc means data=class;
ways 0 1;
class sex /missing;
var height weight;
output out=test1;
run;
ods exclude all;
ods output summary=test2;
proc means data=class;* stackods;
ways 0 1;
class sex /missing;
var height weight;
run;
ods exclude none;
proc print data=test1 noobs;
run;
proc print data=test2 noobs;
run;
When having missing values in the variable listed in the class statement, there is no direct way to distinguish level 0 from level 1.
There are two methods I can think of to eliminate this issue. The first is that _type_=0 and missing SEX is different than _type_=1 and missing SEX. The second is shown below.
data class;
length sex $ 7;
set sashelp.class end=eof;
output;
if eof then
do;
sex='Missing';
age=.A;
output;
end;
run;
proc means data=class;
ways 0 1;
class sex /missing;
var height weight;
output out=test1;
run;
proc means data=class;
ways 0 1;
class age /missing;
var height weight;
output out=test2;
run;
Thanks but it exactly what I said in the question. There are workaround like replacing the missing value by another value. But I'm not looking for a workaround.
If you want _type_ like behavior please describe why OUTPUT OUT= is undesirable.
Not sure why you want it but it looks like it is easy enough with a single class variable.
Let's use the AUTONAME option on the OUTPUT statement so we are comparing similar outputs.
ods exclude all;
ods output summary=test2;
proc means data=class;* stackods;
ways 0 1;
class sex /missing;
var height weight;
output out=test1 n= mean= std= min= max= /autoname;
run;
ods exclude none;
data test2;
set test2;
by sex ;
_type_=not (missing(sex) and first.sex);
run;
proc compare data=test1 compare=test2;
run;
The COMPARE Procedure Comparison of WORK.TEST1 with WORK.TEST2 (Method=EXACT) Variables Summary Number of Variables in Common: 12. Number of Variables in WORK.TEST1 but not in WORK.TEST2: 1. Number of Variables in WORK.TEST2 but not in WORK.TEST1: 3. Number of Variables with Differing Attributes: 10. Observation Summary Observation Base Compare First Obs 1 1 Last Obs 4 4 Number of Observations in Common: 4. Total Number of Observations Read from WORK.TEST1: 4. Total Number of Observations Read from WORK.TEST2: 4. Number of Observations with Some Compared Variables Unequal: 0. Number of Observations with All Compared Variables Equal: 4. NOTE: No unequal values were found. All values compared are exactly equal.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.