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-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!

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.

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