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

I need your help to transpose the data as attached in the file.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You have a few options (to note, if you want proper code, please post test data in the form of a datastep, we don't have time to type data in from a spreadsheet).

Proc transpose * 4 one for each of your variables by famid, then merge the resulting datasets back together byfamid

Eg.

proc transpose data=have out=want1 prefix=year;

  by famid;

  var year;

run;

... same again for each variable

data want;

  merge want1-want4;

  by famid;

run;

 

Also, Arrays - by group, retainall values, array for each varible output on last row.

 

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You have a few options (to note, if you want proper code, please post test data in the form of a datastep, we don't have time to type data in from a spreadsheet).

Proc transpose * 4 one for each of your variables by famid, then merge the resulting datasets back together byfamid

Eg.

proc transpose data=have out=want1 prefix=year;

  by famid;

  var year;

run;

... same again for each variable

data want;

  merge want1-want4;

  by famid;

run;

 

Also, Arrays - by group, retainall values, array for each varible output on last row.

 

data_null__
Jade | Level 19

For this multiple variable to all wide transpose named by OBS number, I think the easiest method is PROC SUMMARY IDGROUP. You do have to know the maximum number of obs per by group and that can't exceed 100.  In other words this work for your example.  I suppose you will reveal the full story in time.

 

data fam;
   input famid year faminc Age Inc @@;
   cards;
1 96 40000 67 12 1 97 40500 33 44 1 98 41000 59 59 2 96 45000 57 80 2 97 45400 47 59 2 98 45800 49 71 3 96 75000 76 84 3 97 76000 10 48 3 98 77000 22 45
;;;;
   run;
proc print;
   run;
proc summary data=fam;
   by famid;
   output out=wide(drop=_: famid_:) idgroup(out[3](_all_)=);
   run;
proc print;
   run;

Capture.PNG

Hi1
Calcite | Level 5 Hi1
Calcite | Level 5

Thanks for ur response

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 2098 views
  • 0 likes
  • 3 in conversation