Solved
Contributor
Posts: 29

# flag unassigned variables as missing

I have a large claims dataset that I flagged for variables of interest but now I want to identify those with no flagged variables,

I flagged these variables by writing a code like this

data want;

set have;

if  ndc=123 then a=1;

else if ndc=456 then b=1;

else if ndc=789 then c=1;

run;

What I have now is

ID  A   B  C

1   1

2

3        1

4

5              1

Then I want to flag ID 2 and 5 for not having any flagged variables

I tried

data want;

set have;

where a ne 1 and b ne 1 and c ne;

run;

The above code did not flag ID 2 and 5

Thanks

Accepted Solutions
Solution
‎12-04-2017 06:34 AM
Super User
Posts: 6,899

## Re: flag unassigned variables as missing

By any chance, did you actually complete the WHERE statement?  It looks like it's missing the number '1' at the end.

Another possibility to consider:  You are using the data set HAVE as input to both DATA steps.  But HAVE doesn't contain A, B, and C.  You need to use the output from the first DATA step as the input to the second DATA step.

Finally, you may find this easier to read:

where sum(0, a, b, c) = 0;

All Replies
Solution
‎12-04-2017 06:34 AM
Super User
Posts: 6,899

## Re: flag unassigned variables as missing

By any chance, did you actually complete the WHERE statement?  It looks like it's missing the number '1' at the end.

Another possibility to consider:  You are using the data set HAVE as input to both DATA steps.  But HAVE doesn't contain A, B, and C.  You need to use the output from the first DATA step as the input to the second DATA step.

Finally, you may find this easier to read:

where sum(0, a, b, c) = 0;

Super User
Posts: 23,928

## Re: flag unassigned variables as missing

[ Edited ]

Try the N or NMISS functions

``if n(a, b, c) < 1 then ..... ;``

leahcho wrote:

I have a large claims dataset that I flagged for variables of interest but now I want to identify those with no flagged variables,

I flagged these variables by writing a code like this

data want;

set have;

if  ndc=123 then a=1;

else if ndc=456 then b=1;

else if ndc=789 then c=1;

run;

What I have now is

ID  A   B  C

1   1

2

3        1

4

5              1

Then I want to flag ID 2 and 5 for not having any flagged variables

I tried

data want;

set have;

where a ne 1 and b ne 1 and c ne;

run;

The above code did not flag ID 2 and 5

Thanks

☑ This topic is solved.