## create list of missing variables by subject

Solved
Occasional Contributor
Posts: 6

# create list of missing variables by subject

Hello,

I have a dataset in which each line is a subject, and I'm interested in creating a new variable that contains a list of 40 possible variables, but only the ones that are missing for each subject. Is there an existing macro for this task? Can anyone help me figure out how to create a variable that contains a list of variables that is unique to each line in a dataset?

Accepted Solutions
Solution
‎05-08-2012 11:23 AM
Super Contributor
Posts: 1,636

## Re: create list of missing variables by subject

try:

improved version:

data have;

input id \$ v1 v2 v3 v4;

cards;

a 1 2 3 .

b 2 3 . .

c 2 . . .

;

data want;

length new \$ 50;

set have;

array _v(*) _numeric_;

do _n_=1 to dim(_v);

if _v(_n_)=. then new=catx('-',new,vname(_v(_n_)));

end;

proc print;run;

Linlin

Message was edited by: Linlin

All Replies
Super Contributor
Posts: 1,636

## Re: create list of missing variables by subject

are the variables numeric or character or both?

Occasional Contributor
Posts: 6

## Re: create list of missing variables by subject

They are all numeric.

Solution
‎05-08-2012 11:23 AM
Super Contributor
Posts: 1,636

## Re: create list of missing variables by subject

try:

improved version:

data have;

input id \$ v1 v2 v3 v4;

cards;

a 1 2 3 .

b 2 3 . .

c 2 . . .

;

data want;

length new \$ 50;

set have;

array _v(*) _numeric_;

do _n_=1 to dim(_v);

if _v(_n_)=. then new=catx('-',new,vname(_v(_n_)));

end;

proc print;run;

Linlin

Message was edited by: Linlin

Occasional Contributor
Posts: 6

## Re: create list of missing variables by subject

I needed to get rid of the retain. Otherwise I was getting repeated variable names in the list, but otherwise, this is perfect. Exactly what I needed. Thank you!

Super Contributor
Posts: 1,636

## Re: create list of missing variables by subject

Hi,

"call missing (your-variable)" gets rid of the missing variable names from previous IDs.

Posts: 5,540

## Re: create list of missing variables by subject

Hi Linlin, since you create a new list for each observation, you don't need the retain, the call missing() or the output statements. It works just as well without them.

PG

PG
Super Contributor
Posts: 1,636

## Re: create list of missing variables by subject

Thank you PG!!!

improved version:

data have;

input id \$ v1 v2 v3 v4;

cards;

a 1 2 3 .

b 2 3 . .

c 2 . . .

;

data want;

length new \$ 50;

set have;

array _v(*) _numeric_;

do _n_=1 to dim(_v);

if _v(_n_)=. then new=catx('-',new,vname(_v(_n_)));

end;

proc print;run;

🔒 This topic is solved and locked.