BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fayyazcivil
Calcite | Level 5

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

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

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;

View solution in original post

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

Reeza
Super User

Use Proc Format:

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

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

stat_sas
Ammonite | Level 13

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;

Reeza
Super User

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.

fayyazcivil
Calcite | Level 5

@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.

Reeza
Super User

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

fayyazcivil
Calcite | Level 5

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 4087 views
  • 6 likes
  • 4 in conversation