BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
triunk
Obsidian | Level 7

Hello SAS users:

 

A message from jmp lover cheating with base SAS: 

 

JMP has an option in Tables that is called "Split by" where you can split a column, mapping several rows on one column to one row in several columns.

 

Any examples on how to do the same thing in SAS?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

I was able to get the example popcorn.jmp data and here is the SAS version of "Split by" as @Reeza mentioning. 

 

data popcorn;
infile datalines dlm='09'x missover;
input popcorn:$8.	oil_amt :$8.	batch:$8.	yield	trial;
datalines;
gourmet	little	large	8.2	2
gourmet	little	large	8.6	1
gourmet	little	small	12.1	1
gourmet	little	small	15.9	2
gourmet	lots	large	9.2	1
gourmet	lots	large	9.8	2
gourmet	lots	small	16	2
gourmet	lots	small	18	1
plain	little	large	8.2	1
plain	little	large	8.8	2
plain	little	small	9.9	1
plain	little	small	10.1	2
plain	lots	large	8.8	2
plain	lots	large	10.4	1
plain	lots	small	7.4	2
plain	lots	small	10.6	1
;
run;

PROC SORT DATA=POPCORN;
BY popcorn	oil_amt	batch	yield	;
RUN;
PROC TRANSPOSE DATA=POPCORN OUT=TRANSPOSE(drop=_name_ ) ;
BY popcorn	oil_amt	batch;
iD trial;
var yield;
RUN;

 

 image.png

 

Thanks,
Suryakiran

View solution in original post

8 REPLIES 8
Reeza
Super User
I think this is a TRANSPOSE task or PROC TRANSPOSE if I understand what you want correctly.

https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/
PeterClemmensen
Tourmaline | Level 20

What does "split a column" mean? 🙂

triunk
Obsidian | Level 7

Wow that was fast response - thank you!

 

This is what JMP means by split by

https://www.jmp.com/support/help/14/split-columns.shtml

 

and this is the different feature they have on transpose

https://www.jmp.com/support/help/14/transpose-rows-and-columns.shtml

 

I think both concepts are related but there are subtle differences

SuryaKiran
Meteorite | Level 14

It would be better if you can provide a sample data you have and how JMP "split by", so that someone here can give you the same result in SAS using your sample data as source.

Thanks,
Suryakiran
triunk
Obsidian | Level 7

Here is an example from JMP webpage:

 

https://www.jmp.com/support/help/14/examples-of-splitting-columns.shtml

 

Here is JSL

 

Data Table( "Popcorn" ) << Split(
Split By( :trial ),
Split( :yield ),
Group( :popcorn ),
Sort by Column Property
)

SuryaKiran
Meteorite | Level 14

I was able to get the example popcorn.jmp data and here is the SAS version of "Split by" as @Reeza mentioning. 

 

data popcorn;
infile datalines dlm='09'x missover;
input popcorn:$8.	oil_amt :$8.	batch:$8.	yield	trial;
datalines;
gourmet	little	large	8.2	2
gourmet	little	large	8.6	1
gourmet	little	small	12.1	1
gourmet	little	small	15.9	2
gourmet	lots	large	9.2	1
gourmet	lots	large	9.8	2
gourmet	lots	small	16	2
gourmet	lots	small	18	1
plain	little	large	8.2	1
plain	little	large	8.8	2
plain	little	small	9.9	1
plain	little	small	10.1	2
plain	lots	large	8.8	2
plain	lots	large	10.4	1
plain	lots	small	7.4	2
plain	lots	small	10.6	1
;
run;

PROC SORT DATA=POPCORN;
BY popcorn	oil_amt	batch	yield	;
RUN;
PROC TRANSPOSE DATA=POPCORN OUT=TRANSPOSE(drop=_name_ ) ;
BY popcorn	oil_amt	batch;
iD trial;
var yield;
RUN;

 

 image.png

 

Thanks,
Suryakiran
Reeza
Super User

I think that’s PROC TRANSPOSE or the TRANSPOSE task. 

To get the second one, don’t include any of the options. 

 

 

triunk
Obsidian | Level 7

So in SAS PROC TRANSPOSE does both jobs of split by and transpose interesting!

 

Thank you!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 1890 views
  • 4 likes
  • 4 in conversation