Obsidian | Level 7

## inverse transpose

Hello Guys,

Can someone write a code to get the folIowing result (TABLE WANT) ? Its a kind inverse transpose that we are used to do.

This is the table that i have.

data have;
input group \$ fields \$ jan commax5.2 feb commax5.2 marc commax5.2;
datalines;
food cheap 1,22 1,55 2,38
food expens 3,02 3,33 4,38
food averag 2,12 2,42 3,23
drink cheap 1,42 1,25 1,38
drink expens 5,04 4,31 5,01
drink averag 3,26 2,42 3,21
;
run;

This is the result that i need.

data want;
input group \$ calc \$ month \$ value commax5.2;
datalines;
food cheap jan 1,22
food cheap feb 1,55
food cheap marc 2,38
food expens jan 3,02
food expens feb 3,33
food expens marc 4,38
food averag jan 2,12
food averag feb 2,42
food averag marc 3,23
drink cheap jan 1,42
drink cheap feb 1,25
drink cheap marc 1,38
drink expens jan 5,04
drink expens feb 4,31
drink expens marc 5,01
drink averag jan 3,26
drink averag feb 2,42
drink averag marc 3,21
;
run;

I apprecciate any help for that.

Thanks

4 REPLIES 4
Lapis Lazuli | Level 10

## Re: inverse transpose

Hi mate,

Try do the same thing in the following code:

``````data have;
input Id (Prod1 Prod2 Prod3)(\$);
cards;
1 A B C
2 D E F
;;;;
run;
proc transpose
name = NewVar1
data = have
out = need(rename=(col1=NewVar2))
;
by id;
var prod:;
run;``````

Hope this helps

Barite | Level 11

## Re: inverse transpose

Here is a solution:

proc sort data=have;by group fields;

proc transpose data=have out=want(rename=(_NAME_ = Month col1 = Value fields = Calc));by group fields;

Pyrite | Level 9

## Re: inverse transpose

```You can try this...
data one;
input food\$ test\$ price1 price2;
array myarr (2)price1 price2;
do i = 1 to 2;
Price = myarr(i);
output;
end;
datalines;
Apple good 10 20
lichi bad 20 40
Apple good 40 70

;
run;
proc print data = one;
run;

```
Opal | Level 21

## Re: inverse transpose

Just a standard transpose. No need to sort.

``````proc transpose data=have name=month
out=want(rename=(col1=value fields=calc));
by group fields notsorted;
var jan feb marc;
run;``````
PG
Discussion stats
• 4 replies
• 2200 views
• 1 like
• 5 in conversation