Solved

Transpose Dataset

Posted on 2011-02-21
2
586 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

617 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