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

I have a dataset with one record per ID. I want to make a dataset with multiple observations per ID (from wide to long).

My original dataset is like,

data have;

input id $ c1-c5 t1-t5;

cards;

1 21 23 34 45 44 22 33 44 55 66

2 21 23 34 45 44 22 33 44 55 66

;

run;

My final dataset is like,

ID    C     T

1     21    22

1     23    33

1     34    44

1     45    55

1     44    66

2     21    22

2     23    33

2     34    44

2     45    55

2     44    66

Is there a way to do the job using ARRAY?

Thanks,

HG

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

how about:

data have;

input id $ c1-c5 t1-t5;

cards;

1 21 23 34 45 44 22 33 44 55 66

2 21 23 34 45 44 22 33 44 55 66

;

run;

data want(keep=id c t);

set have;

array _c(*)c:;

array _t(*) t:;

do i=1 to 5;

  c=_c(i);

  t=_t(i);

output;

end;

run;

proc print;run;

Linlin

View solution in original post

2 REPLIES 2
Linlin
Lapis Lazuli | Level 10

how about:

data have;

input id $ c1-c5 t1-t5;

cards;

1 21 23 34 45 44 22 33 44 55 66

2 21 23 34 45 44 22 33 44 55 66

;

run;

data want(keep=id c t);

set have;

array _c(*)c:;

array _t(*) t:;

do i=1 to 5;

  c=_c(i);

  t=_t(i);

output;

end;

run;

proc print;run;

Linlin

HG
Calcite | Level 5 HG
Calcite | Level 5

It's perfect!

Thanks,

HG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

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
  • 2 replies
  • 1183 views
  • 0 likes
  • 2 in conversation