BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DmytroYermak
Lapis Lazuli | Level 10

Hi all,

 

Could you please help in 'transposing of complex table'. Here below is the code of the table and two pirctures: 1- what it is and 2-how it should be transposed. Thank you!

data test;
	length Patient $1 Examination $7 Visit Finding $1;
	infile datalines dlm='	';
	input Patient Examination Visit Finding;
datalines;
1	SKIN	1	N
1	SKIN	2	N
1	SKIN	3	Y
1	ABDOMEN	1	N
1	ABDOMEN	2	N
1	ABDOMEN	3	Y
;
run;

1 - what I have:

1.jpg

2 - what I need:

2.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Seem very straightforward to me?

data test;
	length Patient $1 Examination $7 Visit Finding $1;
	infile datalines dlm='	';
	input Patient Examination Visit Finding;
datalines;
1	SKIN	1	N
1	SKIN	2	N
1	SKIN	3	Y
1	ABDOMEN	1	N
1	ABDOMEN	2	N
1	ABDOMEN	3	Y
;
run;

proc sort data=test;
  by patient examination;
run;
 
proc transpose data=test out=want prefix=visit;
  by patient examination;
  var finding;
  id visit;
run;

View solution in original post

9 REPLIES 9
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Seem very straightforward to me?

data test;
	length Patient $1 Examination $7 Visit Finding $1;
	infile datalines dlm='	';
	input Patient Examination Visit Finding;
datalines;
1	SKIN	1	N
1	SKIN	2	N
1	SKIN	3	Y
1	ABDOMEN	1	N
1	ABDOMEN	2	N
1	ABDOMEN	3	Y
;
run;

proc sort data=test;
  by patient examination;
run;
 
proc transpose data=test out=want prefix=visit;
  by patient examination;
  var finding;
  id visit;
run;
DmytroYermak
Lapis Lazuli | Level 10

Thank you, RW9! It is straightforward to you, but not for me as I am just studying 'proc transpose'.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Ah, simpest way to think about it is: one variable going up then proc transpose, multiple variables going up then arrays.  You can find quite a lot of information by searching reshaping data, for instance:

https://communities.sas.com/t5/forums/searchpage/tab/message?advanced=false&allow_punctuation=false&...

ballardw
Super User

Is this new data set input to a model or other statistical analysis or only used to print a report?

 

If you are printing a report for people to read than one of the report procedures such as Proc Report or Tabulate may be of interest.

DmytroYermak
Lapis Lazuli | Level 10
Hi ballardw, it is a step from sdtm to adam.
art297
Opal | Level 21

@DmytroYermak: While you already have your answer, @RW9's suggested code left off one thing if you want your resulting file to actually appear the way you showed it in your original post, namely with the transposed variables ending with the string 'Findings'.

 

You can easily do that by using PROC TRANSPOSE's suffix option. e.g.:

proc transpose data=test out=want (drop=_:)
    prefix=Visit
    suffix=Findings;
  by patient examination;
  var finding;
  id visit;
run;

Art, CEO, AnalystFinder.com 

DmytroYermak
Lapis Lazuli | Level 10
Thank you, art297! I have used your recommendation. Just one quiestion: what does ":" in the option "drop" mean?
art297
Opal | Level 21

@DmytroYermak: The colon is a wild card. Thus drop=_: says drop any variable that begins with an underscore.

 

PROC TRANSPOSE automatically creates one or more system variables .. each beginning with an underscore.

 

Art, CEO, AnalystFinder.com

 

DmytroYermak
Lapis Lazuli | Level 10
Thanks!

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 9 replies
  • 1189 views
  • 1 like
  • 4 in conversation