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.

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
  • 7 replies
  • 2776 views
  • 6 likes
  • 4 in conversation