Hi,
I would like to do proc means on some variables on a dataset. I do have missing observations for each variable and it's set as 999. How do I exclude those missing observations from analysis.
proc means data=new;
var age educ sadyrs pslgthyrs;
run;
I only know how to do it for each variable separately (see below):
proc means data=new (where=(age ne 999));
var age;
run;
You cannot easily. You could try and combine the where clause but then all records with any variable with 999 would be excluded.
Ideally you can recode the 999 to a SAS missing value. If you have multiple issues for missing you can use multiple missing codes.
This is an example that would create a view and then you would run PROC MEANS on it. It only runs when you call proc means and doesn't create a data set that lingers around.
data temp_recode/ view= temp_recode ;
set have;
array recode(*) var1-var200;
do i=1 to dim(recode);
if recode(i) = 999 then recode(i) = .N; *not applicable;
else if recode(i) = 888 then recode(i)=.K; *did not know;
else if recode(i) = 777 then recode(i) = .M; *missing;
end;
run;
@starz4ever2007 wrote:
Hi,
I would like to do proc means on some variables on a dataset. I do have missing observations for each variable and it's set as 999. How do I exclude those missing observations from analysis.
proc means data=new;
var age educ sadyrs pslgthyrs;
run;
I only know how to do it for each variable separately (see below):
proc means data=new (where=(age ne 999));
var age;
run;
You cannot easily. You could try and combine the where clause but then all records with any variable with 999 would be excluded.
Ideally you can recode the 999 to a SAS missing value. If you have multiple issues for missing you can use multiple missing codes.
This is an example that would create a view and then you would run PROC MEANS on it. It only runs when you call proc means and doesn't create a data set that lingers around.
data temp_recode/ view= temp_recode ;
set have;
array recode(*) var1-var200;
do i=1 to dim(recode);
if recode(i) = 999 then recode(i) = .N; *not applicable;
else if recode(i) = 888 then recode(i)=.K; *did not know;
else if recode(i) = 777 then recode(i) = .M; *missing;
end;
run;
@starz4ever2007 wrote:
Hi,
I would like to do proc means on some variables on a dataset. I do have missing observations for each variable and it's set as 999. How do I exclude those missing observations from analysis.
proc means data=new;
var age educ sadyrs pslgthyrs;
run;
I only know how to do it for each variable separately (see below):
proc means data=new (where=(age ne 999));
var age;
run;
I have tried your code, but does not work. The values (Numbers )in the table still the same do not convert to missing value.
@Malk020 wrote:
I have tried your code, but does not work. The values (Numbers )in the table still the same do not convert to missing value.
In cases like these, we need to see the EXACT code you are using, and also a portion of your data.
DO NOT ATTACH FILES. Include the code you are using in the code box (click on the little running man icon) and include a portion of your data as SAS data step code (instructions).
I think i do not understand you.
Please kindly see the code. The code is run perfectly as i want and makes two tables. The problem is in the second Proc Tabulate(Numerical variables) when I run the code I got some values over 1000 and I just want to set up them as a missing value!!
proc contents data = .. ;
run;
* Categorical Variables;
PROC FREQ DATA = …;
TABLES ;
RUN;
*Numerical Variables;
proc means data =…;
var ;
RUN;
*** Crate a format *****;
proc format;;
value
1=''
2='';
value
1 = 'M'
2= 'F';
run;
*** Crate a table save it as CSV format *****;
OPTIONS MISSING = '';
ODS CSV FILE = '.csv';
PROC TABULATE DATA =..
CLASS / Missing;
CLASSLEV
TABLE
ALL (..)*
(N= COLPCTN=*f=5.1)
, (… ='' ALL='Total')
misstext='0';
format ..;
RUN;
PROC TABULATE DATA…. = ;
CLASS …..;
VAR…. ;
TABLE
(…. )*(MEAN=
STD=), (.. ='' ALL='Total')
misstext='0';
format.;
run;
CLOSE
You said you tried the code above where 999 is converted to .N
but you don't show anything of the sort in your code.
That's the code we need to see.
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 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.