Desktop productivity for business analysts and programmers

TRANSPOSE an entire table

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

TRANSPOSE an entire table

Hi,

I am trying to use PROC TRANSPOSE to transpose from wide to narrow and entire dataset.

This is what I have.

IDSALARYNAMEHIRE_DATEBONUSDEPT
001001100,000JONES SMITH0101201010,000ADMIN
00100258,362HARRY WIZARD020520055,600SALES
00100385,254JOHN ADAMS101020093,055SALES

This is the expected outcome I need.

ID001001001002001003
SALARY100,00058,36285,254
NAMEJONES SMITHHARRY WIZARDJOHN ADAMS
HIRE_DATE010120100205200510102009
BONUS10,0005,6003,055
DEPADMINSALESSALES

I am trying to use PROC TRANSPOSE, but I havent been able to obtain the expected result.  Any help?


Accepted Solutions
Solution
‎10-24-2014 11:28 AM
Respected Advisor
Posts: 3,775

Re: TRANSPOSE an entire table

data id;
   infile cards firstobs=2 dsd dlm='|';
  
input ID :$4. SALARY:comma. NAME:$16. HIRE_DATE:mmddyy. BONUS:comma. DEPT :$8.;
  
format salary bonus comma12. hire_date mmddyy10.;
  
cards;
ID,SALARY,NAME,HIRE_DATE,BONUS,DEPT
1001|100,000|JONES SMITH|1012010|10,000|ADMIN
1002|58,362|HARRY WIZARD|2052005|5,600|SALES
1003|85,254|JOHN ADAMS|10102009|3,055|SALES
;;;;
proc print;
  
run;
proc transpose data=id out=id2 name=ID;
   id id;
   var salary--dept;
   run;
proc print;
  
run;


10-24-2014 10-26-27 AM.png

View solution in original post


All Replies
Solution
‎10-24-2014 11:28 AM
Respected Advisor
Posts: 3,775

Re: TRANSPOSE an entire table

data id;
   infile cards firstobs=2 dsd dlm='|';
  
input ID :$4. SALARY:comma. NAME:$16. HIRE_DATE:mmddyy. BONUS:comma. DEPT :$8.;
  
format salary bonus comma12. hire_date mmddyy10.;
  
cards;
ID,SALARY,NAME,HIRE_DATE,BONUS,DEPT
1001|100,000|JONES SMITH|1012010|10,000|ADMIN
1002|58,362|HARRY WIZARD|2052005|5,600|SALES
1003|85,254|JOHN ADAMS|10102009|3,055|SALES
;;;;
proc print;
  
run;
proc transpose data=id out=id2 name=ID;
   id id;
   var salary--dept;
   run;
proc print;
  
run;


10-24-2014 10-26-27 AM.png
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 224 views
  • 0 likes
  • 2 in conversation