Setting variable values to missing for multiple variables

Reply
Regular Contributor
Posts: 188

Setting variable values to missing for multiple variables

I have a set of variables which goes like a94-a114 b94-b114 and so on.

I want to set values of a94-a114 to .(dot) if its spaces.

I was trying this:

array var[21] a94-a114;

do i=1 to 21;

if var=' ' then var=.;

end;

But it says variable already exist.

Super User
Super User
Posts: 7,401

Re: Setting variable values to missing for multiple variables

Could I check what the intent is here.  It seems like you are dealing with character variables, why then would you want a numeric missing value?

Without test data I would guess at:

data want;

     set have;

     array a{21};

     do I=1 to 21;

          if a{I}=' ' then a{I}='.';

     end;

run;

Should work, you are missing the quotes around the ., so its probably telling you that you are attempting to assign numeric to character.

Super User
Posts: 6,936

Re: Setting variable values to missing for multiple variables

Could you provide information about the data set and its variables, and the actual log?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 10,500

Re: Setting variable values to missing for multiple variables

The error is that the code is attempting to create a numeric to hold . but you have a character variable already with the same name.

Trusted Advisor
Posts: 1,204

Re: Setting variable values to missing for multiple variables

Not sure why are you getting message but this works fine for me.

data have;
infile datalines missover;
input a1 $   a2 $   a3 $;
datalines;
a        b        
c        d       
e        f      g
h        i      j
;

data want(drop=i);
set have;
array var[3] a1-a3;
do i=1 to 3;
if var=' ' then var=.;
end;
run;

Contributor
Posts: 26

Re: Setting variable values to missing for multiple variables

Looks like you're trying to redefine a character array to numeric. Try if var=' ' then var='.'; notice the quotes around the period.

Ask a Question
Discussion stats
  • 5 replies
  • 254 views
  • 0 likes
  • 6 in conversation