Solved

Transpose Dataset

Posted on 2011-02-21
2
581 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

828 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