Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Transpose Dataset

Posted on 2011-02-21
2
Medium Priority
?
593 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 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

886 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