Turn on suggestions

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

Showing results for

Options

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 02-22-2019 12:24 PM
(934 views)

Hello All.

I am currently a student and working on a [simple] problem where we must count the missing values in the DATA SET. Can anyone tell me what I'm doing wrong? Here is my source data and my code thus far:

1 2 3

4 5

6 7 8

9 10 11

4 5

6 7 8

9 10 11

```
data miss;
infile "/folders/myfolders/Chapter_8/missing.txt";
input A : $1.
B : $1.
C : $1.;
if missing(A) then MissA + 1;
else if missing(B) then MissB + 1;
else if missing(C) then MissC + 1;
run;
```

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@yautja33 wrote:

Hello All.

I am currently a student and working on a [simple] problem where we must count the missing values in the DATA SET. Can anyone tell me what I'm doing wrong? Here is my source data and my code thus far:

Tell us what you see that is wrong.

And we don't have your .txt file, so we can't run this ourselves.

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

A few things to think about ...

Did you mean to read in your variables as character variables instead of numeric? That's the impact of adding $ to the INPUT statement.

There is nothing in your DATA step that prints the results.

Adding ELSE to the logic is probably the wrong thing to do. If A has a missing value, you should not skip over B. You still need to inspect whether B has a missing value.

The syntax you use to check for missing values looks like this:

missing(A)

That won't compute. You could use this instead:

A = " "

If you switch and read the variables as numeric, you would check for a missing value using:

A = .

So in context you might end up with:

if A = . then MissA + 1;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

If you have a file of any size (both in terms of number of observations and number of variables) you're going to find it much more efficient to use one of the procedures which gives you this statistic. I'd use Proc Means - here's an example using a modified version of SASHELP.CARS

```
data cars;
set sashelp.cars;
if type="SUV" then msrp=.;
if origin="Asia" then invoice=.;
if make="Acura" then origin="";
run;
proc means data=cars nmiss n;
run;
```

If you run that code you'll see it gives you the total number of missing and non-missing observations for all the numeric variables without you having to specify the variable names. You'll also see that you don't get a figure for the missing values in the character variable ORIGIN which I introduced in the data step. To do that you can use a trick I learnt from Rick Wicklin's Blog post here -> https://blogs.sas.com/content/iml/2011/09/19/count-the-number-of-missing-values-for-each-variable.ht...

```
proc format;
value $missfmt ' '='Missing' other='Not Missing';
value missfmt . ='Missing' other='Not Missing';
run;
proc freq data=cars;
format _CHAR_ $missfmt.; /* apply format for the duration of this PROC */
tables _CHAR_ / missing missprint nocum nopercent;
format _NUMERIC_ missfmt.;
tables _NUMERIC_ / missing missprint nocum nopercent;
run;
```

The output looks different to the previous example as it uses Proc Freq but it gives you values for all variables, including the character ones.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Correction:

```
data miss;
infile "/folders/myfolders/Chapter_8/missing.txt" dlm=' ' missover;
input A : $1.
B : $1.
C : $1.;
if missing(A) then MissA + 1;
else if missing(B) then MissB + 1;
else if missing(C) then MissC + 1;
run;
```

Please let us know if it worked for you.

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

Upcoming Events

- Ask the Expert: Tricks for Report Builders: Report Design Best Practices | 06-Aug-2024
- SAS Bowl XLII, The SAS Hackathon 2024 | 14-Aug-2024
- Ask the Expert: Top Tips for SAS®9 Programmers Moving to SAS® Viya® | 15-Aug-2024
- Ask the Expert: Workload Orchestration in SAS® Viya® 4 | 22-Aug-2024
- Ask the Expert: Solving Multi-Objective Optimization Models in SAS® Optimization | 29-Aug-2024
- WUSS 2024 | 04-Sep-2024
- Ask the Expert: Executing SAS Analytics From R Shiny Applications | 05-Sep-2024

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.