Help using Base SAS procedures

how to assign sequential number vars to alpha vars

Accepted Solution Solved
Reply
Super Contributor
Posts: 395
Accepted Solution

how to assign sequential number vars to alpha vars

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;


Accepted Solutions
Solution
‎01-29-2012 12:47 PM
Super Contributor
Posts: 1,636

how to assign sequential number vars to alpha vars

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

View solution in original post


All Replies
Solution
‎01-29-2012 12:47 PM
Super Contributor
Posts: 1,636

how to assign sequential number vars to alpha vars

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

Valued Guide
Posts: 765

how to assign sequential number vars to alpha vars

hi ... might add a LENGTH statement when using CAT functions, otherwise length of POSTAL is 200

Super Contributor
Posts: 1,636

how to assign sequential number vars to alpha vars

Thank you Mike. I will add a length statement next time.

Linlin

Super Contributor
Posts: 395

how to assign sequential number vars to alpha vars

Thank you Linlin,  very helpful.

Super Contributor
Posts: 395

how to assign sequential number vars to alpha vars

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

PROC Star
Posts: 7,362

how to assign sequential number vars to alpha vars

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;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 173 views
  • 0 likes
  • 4 in conversation