Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Transpose Dataset

Posted on 2011-02-21
2
Medium Priority
?
590 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 1000 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 1000 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
What we learned in Webroot's webinar on multi-vector protection.
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

718 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