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.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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