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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;


 

View solution in original post

6 REPLIES 6
Reeza
Super User

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;


 

Malk020
Fluorite | Level 6

I have tried your code, but does not work. The values (Numbers )in the table still the same do not convert to missing value. 

PaigeMiller
Diamond | Level 26

@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).

--
Paige Miller
Malk020
Fluorite | Level 6

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 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Reeza
Super User
And when you post code please use a code box and format it. As posted, your code isn't legible.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 6 replies
  • 2596 views
  • 2 likes
  • 4 in conversation