Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Some simple data management questions (missing val...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-14-2010 01:43 PM

Hello all-

Firstly, suppose I have a data set that has many variables with missing values and i want to only keep the observations with no missing values. Is there a way I can tell SAS to check all the variables in my data set as opposed to one at a time as in:

data weight1;

set weight;

where (var1 ^=. AND var2^=. AND var3^=. etc);

run;

Secondly, how can I add a new row of data to an existing dataset. For example, if I have a dataset and I want to add a new observation var1=x, var2=y, var3=z, etc., how can I do this?

Thanks

Geo

Firstly, suppose I have a data set that has many variables with missing values and i want to only keep the observations with no missing values. Is there a way I can tell SAS to check all the variables in my data set as opposed to one at a time as in:

data weight1;

set weight;

where (var1 ^=. AND var2^=. AND var3^=. etc);

run;

Secondly, how can I add a new row of data to an existing dataset. For example, if I have a dataset and I want to add a new observation var1=x, var2=y, var3=z, etc., how can I do this?

Thanks

Geo

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-14-2010 02:09 PM

You can use the SUM function to add all the numeric variables in a row; if the result is missing, then all variables in the row are missing.

data a;

set sashelp.class;

rowsum=sum(of _numeric_);

run;

You can add a new row with the OUTPUT statement in a SAS data step

data a;

set sashelp.class end=eof;

output;

if eof then do;

age=14;

height=56;

weight=99;

output;

end;

run;

data a;

set sashelp.class;

rowsum=sum(of _numeric_);

run;

You can add a new row with the OUTPUT statement in a SAS data step

data a;

set sashelp.class end=eof;

output;

if eof then do;

age=14;

height=56;

weight=99;

output;

end;

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-14-2010 02:21 PM

Paige-

What if some of my variables are categorical and are missing?

What if some of my variables are categorical and are missing?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-14-2010 02:46 PM

I don't really have a simple example in that case. Probably you need to use ARRAYs.

But I have a question for you. Why make an effort to delete rows with all missing values? Leaving them in the data set doesn't hurt anything, does it?

But I have a question for you. Why make an effort to delete rows with all missing values? Leaving them in the data set doesn't hurt anything, does it?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-14-2010 03:49 PM

Please still answer Paige's question but, if you need to identify records that have missing values AND you are using SAS 9.2, take a look at the cmiss function.

Art

Art

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-14-2010 04:31 PM

One example with using CMISS and NMISS is demonstrated below, along with the special variable-type array references (all variables of a type).

9 data _null_;

10 retain a1 . a2 0 b1 'x' b2 'y';

11 if cmiss(of _character_) then put 'char-yep';

12 if nmiss(of _numeric_) then put 'num-yep';

13 run;

num-yep

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.00 seconds

Scott Barry

SBBWorks, Inc.

9 data _null_;

10 retain a1 . a2 0 b1 'x' b2 'y';

11 if cmiss(of _character_) then put 'char-yep';

12 if nmiss(of _numeric_) then put 'num-yep';

13 run;

num-yep

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.00 seconds

Scott Barry

SBBWorks, Inc.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-14-2010 04:41 PM

Scott,

I don't have 9.2, thus can't test it, but I was under the impression that CMISS handled BOTH numeric and character. Thus, I would think that one could use:

CMISS (of _all_)

Art

I don't have 9.2, thus can't test it, but I was under the impression that CMISS handled BOTH numeric and character. Thus, I would think that one could use:

CMISS (of _all_)

Art

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-14-2010 04:55 PM

Thanks for the tip, Art - I tested it with SAS 9.2 and you are correct.

Scott Barry

SBBWorks, Inc.

Scott Barry

SBBWorks, Inc.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-14-2010 06:03 PM

Paige-

I am working with the proc mixed statement doing a longitudinal analysis and I have missing data for some of my variables which are both continuous and categorical.

I know proc mixed automatically removes the missing observations but I wanted to have a separate data set which contained all the non-missing values for procs that dont play nice with missing values (such as proc iml)

Art and Scott-

Thanks for the help. Here what I did and it worked out nicely:

**data weight1;**

set weight1;

if cmiss(of _all_) then miss='Y';

else miss='N';

run;

data nomiss;

set weight1;

where miss='N';

drop miss;

run;

I am working with the proc mixed statement doing a longitudinal analysis and I have missing data for some of my variables which are both continuous and categorical.

I know proc mixed automatically removes the missing observations but I wanted to have a separate data set which contained all the non-missing values for procs that dont play nice with missing values (such as proc iml)

Art and Scott-

Thanks for the help. Here what I did and it worked out nicely:

set weight1;

if cmiss(of _all_) then miss='Y';

else miss='N';

run;

data nomiss;

set weight1;

where miss='N';

drop miss;

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-15-2010 08:54 AM

which can be shortened to

data nomiss;

set weight1;

if cmiss(of _all_) then delete;

run;

data nomiss;

set weight1;

if cmiss(of _all_) then delete;

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-15-2010 10:29 AM

which, in turn, can be shortened to: :-)

[pre]

data nomiss;

set weight1;

if ^cmiss(of _all_);

run;

[/pre]

[pre]

data nomiss;

set weight1;

if ^cmiss(of _all_);

run;

[/pre]