BookmarkSubscribeRSS Feed
munitech4u
Quartz | Level 8

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.

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

ballardw
Super User

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.

stat_sas
Ammonite | Level 13

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;

rcwright
Calcite | Level 5

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

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 656 views
  • 0 likes
  • 6 in conversation