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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

6 REPLIES 6
Linlin
Lapis Lazuli | Level 10

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

MikeZdeb
Rhodochrosite | Level 12

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

Linlin
Lapis Lazuli | Level 10

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

Linlin

podarum
Quartz | Level 8

Thank you Linlin,  very helpful.

podarum
Quartz | Level 8

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

art297
Opal | Level 21

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;

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

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