## Replace values in array

Solved
Occasional Contributor
Posts: 14

# Replace values in array

Hello.

I've a column vector array 61312*1. Values ranges from 0 to 20. I need to replace the values (0 to 20) with the below mentioned values(0 to 7):

0=0, 1=1, 2,3=2, 4=3, 5,6,13=4, 7,8,9=5, 10,11,12,16=6, 14,15,17,18,19,20=7

Accepted Solutions
Solution
‎07-07-2014 11:34 AM
Posts: 1,270

## Re: Replace values in array

If just interested in displaying then you can try proc format.

data have;

do vector=1 to 20;

output;

end;

run;

proc format;

value vector

0=0

1=1

2,3=2

4=3

5,6,13=4

7,8,9=5

10,11,12,16=6

14,15,17,18,19,20=7

;

data want;

set have;

format vector vector.;

run;

All Replies
Super User
Posts: 9,599

## Re: Replace values in array

Not sure what the column vector array means, but with normal arrays you could use if statements, select/when statements, in fact any conditional logic in a datastep or sql to change the information e.g.:

if the_array{iterator}=0 then 0;

if the_array{iterator}=1 then 1;

...

if the_array{iterator} in (14,15,16,17,18,19,20) then 7;

Super User
Posts: 23,724

## Re: Replace values in array

Use Proc Format:

Here's a good reference on how to recode something:

http://www2.sas.com/proceedings/sugi30/001-30.pdf

Solution
‎07-07-2014 11:34 AM
Posts: 1,270

## Re: Replace values in array

If just interested in displaying then you can try proc format.

data have;

do vector=1 to 20;

output;

end;

run;

proc format;

value vector

0=0

1=1

2,3=2

4=3

5,6,13=4

7,8,9=5

10,11,12,16=6

14,15,17,18,19,20=7

;

data want;

set have;

format vector vector.;

run;

Super User
Posts: 23,724

## Re: Replace values in array

You say an array of 613121*1, which in my head is 60K rows and 1 column? If so this isn't considered an array in SAS. An array in SAS is in a single row, as such, 1*61K values.

Occasional Contributor
Posts: 14

## Re: Replace values in array

@Reeza, yes it has 60K rows and I column.

I am sorry I didn't know about that. Now I know what is array in SAS.

Super User
Posts: 23,724

## Re: Replace values in array

That's fine, its just that @RW9 code won't work for that, you'll need something closer to stat@sas code.

SAS Learning Module: Creating and recoding variables in SAS

Occasional Contributor
Posts: 14

## Re: Replace values in array

I am reading Proc Format, and let's see how it works.

🔒 This topic is solved and locked.