Hi, I have about 120 Postal Codes or FSA's (M1P, M2H, .. V3T, etc..) I would like to assign a sequence name to each one. So the first A0A would have something like FSA1 and the next AOB would have like FSA2 and last V0W wold have FSA120. And I'd have a table for reference. I'm doing this becasue I need to use proc similarity and the TARGET variables need to be in a numeric sequence. Thanks.
Have:
FSA
A0A
A0B
A0C
M1P
M2H
N9Y
.....
VOW
Want:
FSA POSTAL
A0A FSA1
A0B FSA2
A0C FSA3
M1P FSA4
M2H FSA5
N9Y FSA6
...
V0W FSA120;
Hi podarum,
Please remembe to give people credit if they provide you with correct answer. Thank you!
data have;
input fsa$;
cards;
A0A
A0B
A0C
M1P
M2H
N9Y
;
data want;
set have;
postal=cats('fsa',_n_);
proc print;run;
Obs fsa postal
1 A0A fsa1
2 A0B fsa2
3 A0C fsa3
4 M1P fsa4
5 M2H fsa5
6 N9Y fsa6
Linlin
Hi podarum,
Please remembe to give people credit if they provide you with correct answer. Thank you!
data have;
input fsa$;
cards;
A0A
A0B
A0C
M1P
M2H
N9Y
;
data want;
set have;
postal=cats('fsa',_n_);
proc print;run;
Obs fsa postal
1 A0A fsa1
2 A0B fsa2
3 A0C fsa3
4 M1P fsa4
5 M2H fsa5
6 N9Y fsa6
Linlin
hi ... might add a LENGTH statement when using CAT functions, otherwise length of POSTAL is 200
Thank you Mike. I will add a length statement next time.
Linlin
Thank you Linlin, very helpful.
Hi, when I put them in proc transpose, I get the postal coulms (eg. FSA1, FSA2..FSA120) sorted as such : FSA1, FSA10, FSA100, FSA101, FSA2....FSA99., but is there a way to sort them numerically as FSA1 FSA2 FSA3...FSA120. Thanks
Easiest way, I think, would be to assign them with leading zeros. e.g.:
data want;
set have;
postal=cats('fsa',put(_n_,z3.));
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.