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.
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.
Could you provide information about the data set and its variables, and the actual log?
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.
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;
Looks like you're trying to redefine a character array to numeric. Try if var=' ' then var='.'; notice the quotes around the period.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.