BookmarkSubscribeRSS Feed
Augusto
Obsidian | Level 7

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
DartRodrigo
Lapis Lazuli | Level 10

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

Steelers_In_DC
Barite | Level 11

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;

pearsoninst
Pyrite | Level 9
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;
PGStats
Opal | Level 21

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

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2200 views
  • 1 like
  • 5 in conversation