Solved

Transpose Dataset

Posted on 2011-02-21
2
577 Views
Last Modified: 2013-11-16
How do I write SAS code to transpose the Before table into the After table, attached? Before.xls After.xls
0
Comment
Question by:mikecharters
2 Comments
 
LVL 14

Accepted Solution

by:
Aloysius Low earned 250 total points
ID: 34948834
Are you expecting Year and Month to be a column header or values in a column?

What I've got here is Year and Month as values in a column. Will need to do additional filtering to achieve what you want. If you want Year and Month to be column headers then you'll need to combine them into 1 value before transpose.


PROC SORT
      DATA=TEST.BEFORE(KEEP=Year Month Value Location)
      OUT=WORK.SORTED_BEFORE;
      BY Location;
RUN;

PROC TRANSPOSE DATA=WORK.SORTED_BEFORE
      OUT=WORK.TRANSPOSE_AFTER;
      BY Location;
      VAR Year Month Value;
RUN;
0
 
LVL 11

Assisted Solution

by:theartfuldazzler
theartfuldazzler earned 250 total points
ID: 34949317
Hi

Iowaloysius is correct, but if you want closer to your given output, I would add ID statements to the PROC Transpose. Also, to make the columns "pretty" I would create a 'date' field:



This gives you the form you are looking for, but the columns are not "pretty"

To make it "pretty", you would need to create a date field:

DATA Test.Before;
  SET Test.Before;
Date = INPUT(COMPRESS('01'||Month||YEAR), date9.);
FORMAT Date MONYY.;
RUN;


PROC SORT
      DATA=TEST.BEFORE(KEEP=Year Month Value Location Date)
      OUT=WORK.SORTED_BEFORE;
      BY Location;
RUN;

PROC TRANSPOSE DATA=WORK.SORTED_BEFORE
      OUT=WORK.TRANSPOSE_AFTER;
      BY Location;
      VAR  Value ;
        ID Date;
RUN;

... Alternatively, you could do: "ID Month Year" - but the output is not as nice.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now