DATA Step, Macro, Functions and more

Transposing Dataset

Accepted Solution Solved
Reply
Contributor sss
Contributor
Posts: 65
Accepted Solution

Transposing Dataset

Hi,

I have Excel file,Raw_data sheet contains the raw data and output sheet contains the desired output i am looking for.

I want to transpose the dataset, but i am not able to do that with normal trans pose procedure.

Now for example, For autos variable i have total 4 row with 1 as value and the count will be 4. Next total price will be 2.11.

similarly i want to Three variable auto , book, Intent which have count and total price for the.

The raw data and output is attached.

Will be very kindful for your help.

Attachment
Attachment

Accepted Solutions
Solution
‎02-02-2014 06:19 PM
Respected Advisor
Posts: 4,646

Re: Transposing Dataset

One way to do it with SQL is:

proc sql;

create table output as

select "Autos" as Query, sum(autos*DSQ) as DSQsum, sum(autos*price) as PriceSum from have

union all

select "Intent", sum(Intent*DSQ), sum(Intent*price) from have

union all

select "Book", sum(Book*DSQ), sum(Book*price) from have;

select * from output;

quit;

PG

PG

View solution in original post


All Replies
Solution
‎02-02-2014 06:19 PM
Respected Advisor
Posts: 4,646

Re: Transposing Dataset

One way to do it with SQL is:

proc sql;

create table output as

select "Autos" as Query, sum(autos*DSQ) as DSQsum, sum(autos*price) as PriceSum from have

union all

select "Intent", sum(Intent*DSQ), sum(Intent*price) from have

union all

select "Book", sum(Book*DSQ), sum(Book*price) from have;

select * from output;

quit;

PG

PG
Contributor sss
Contributor
Posts: 65

Re: Transposing Dataset

Thank u PGStat. Smiley Happy it works

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 221 views
  • 0 likes
  • 2 in conversation