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

Hi all,

I want to do the following:

IndexZCTA
135010


236830368313683236849
33650736509

436502


to

IndexZCTA
135010
236830
236831
236832
236849
336507
336509
436502

I have some rows with over 90 columns.

I appreciate your help in advance!

Thanks,

Chris

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

If all of your columns (except for index) are called zctaX (where x is an incremental number), and your data file is called 'have', then the following will do what you want:

data have;

  input Index ZCTA1-ZCTA4;

  cards;

1 35010 . . .

2 36830 36831 36832 36849

3 36507 36509 . .

4 36502 . . .

;

proc transpose data=have

  out=want (rename=(col1=zcta) where=(not missing(zcta)));

  by index;

  var ZCTA:;

run;

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

If all of your columns (except for index) are called zctaX (where x is an incremental number), and your data file is called 'have', then the following will do what you want:

data have;

  input Index ZCTA1-ZCTA4;

  cards;

1 35010 . . .

2 36830 36831 36832 36849

3 36507 36509 . .

4 36502 . . .

;

proc transpose data=have

  out=want (rename=(col1=zcta) where=(not missing(zcta)));

  by index;

  var ZCTA:;

run;

Linlin
Lapis Lazuli | Level 10

data have;

infile datalines missover;

input index zcta z1-z3;

datalines;

1          35010

2          36830          36831          36832          36849

3          36507          36509

4          36502

run;

data want(keep=index zcta);

  set have;

  array _n(*) zcta z1-z3;

  do i=1 to dim(_n) while (_n(i) ne .);

  zcta=_n(i);

  output;

  end;

  run;

  option nocenter;

  proc print;run;

Obs    index     zcta

  1       1      35010

2       2      36830

3       2      36831

4       2      36832

5       2      36849

6       3      36507

7       3      36509

8       4      36502

Linlin

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 4515 views
  • 4 likes
  • 3 in conversation