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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.