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.
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;
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;
Use Proc Format:
Here's a good reference on how to recode something:
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;
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.
@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.
That's fine, its just that @RW9 code won't work for that, you'll need something closer to stat@sas code.
I am reading Proc Format, and let's see how it works.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.