Desktop productivity for business analysts and programmers

Create a Column Heading from Each Distinct Value & then Transpose Data.

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

Create a Column Heading from Each Distinct Value & then Transpose Data.

I apologize in advance, because I doubt that this screenshot is the most helpful format,  but I don't know how to post a table.

 

What I'd like to do is go from the dataset on the left to the one on the right, but, as I'm just beyond a beginner in SAS, I don't have any idea how to do it.  Any feedback would be appreciated, including feedback about how to post the data from this screenshot in a more user friendly fashion.  Thanks.

 

SAS_PIC.png


Accepted Solutions
Solution
‎08-05-2016 11:46 AM
Regular Contributor
Posts: 236

Re: Create a Column Heading from Each Distinct Value & then Transpose Data.

 

data emp_sal;
input Empid $ year salary;
datalines;
Emp1 1996 2596
Emp1 1997 2600
Emp2 1997 8596
Emp2 1998 8700
Emp3 1997 6200
Emp3 1998 6500
Emp3 1999 6800
;

proc transpose data=emp_sal out=transpose_emp_sal;
by Empid;
ID year;
run;

 

I have given the most simple proc transpose without using much option.

Read about proc transpose and exlore.

 

 

Regarding posting question,  Any way that can be understood, it is nice that you have shown what is your input dataset and what do you wnat as output. 

View solution in original post


All Replies
Solution
‎08-05-2016 11:46 AM
Regular Contributor
Posts: 236

Re: Create a Column Heading from Each Distinct Value & then Transpose Data.

 

data emp_sal;
input Empid $ year salary;
datalines;
Emp1 1996 2596
Emp1 1997 2600
Emp2 1997 8596
Emp2 1998 8700
Emp3 1997 6200
Emp3 1998 6500
Emp3 1999 6800
;

proc transpose data=emp_sal out=transpose_emp_sal;
by Empid;
ID year;
run;

 

I have given the most simple proc transpose without using much option.

Read about proc transpose and exlore.

 

 

Regarding posting question,  Any way that can be understood, it is nice that you have shown what is your input dataset and what do you wnat as output. 

Grand Advisor
Posts: 17,396

Re: Create a Column Heading from Each Distinct Value & then Transpose Data.

Look into Transpose, in EG I believe it's a task. 

If your coding it's proc transpose. 

 

If you want to get better answers including code, it helps to post data as a data step. 

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

At aminimum paste it in as text rather than an image. 

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 298 views
  • 2 likes
  • 3 in conversation