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

proc transpose data=adds out=trans_adds let;
by usubjid ;
id param;
var avalc;
run;

 

i am using the above step but can i make this possible so that i can transpose in data step?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Can you show what you want to get? Please reduce your data to just enough columns and rows to demonstrate the issue and post it into the question using the Insert SAS code icon.  So both input and output data. Make sure to include a problem case that has duplicate rows and be clear about how you want it handled.

 

You also seems to be using the wrong variable for the ID. PARAMCD looks more like a variable name than PARAM which looks like a sentence in your data.

 

If your ID variables are not enough to uniquely identify rows then you need to add another variable.  So you might add a sequence number for each distinct value of UNIQUEID, PARAM.

proc sort data=adds out=fixed_adds ;
  by usubjid paramcd;
run;
data fixed_adds ;
  by unsubjid paramcd;
  seq+1;
  if first.paramcd then seq=1;
run;

proc transpose data=fixed_adds out=trans_adds ;
by usubjid ;
id paramcd seq;
var avalc;
run;

Then you will get variables like PRIMREAS1, PRIMREAS2 and SECREAS1, SECREAS2, ...

View solution in original post

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, you can do that in a datastep.  Why would you want to do that however, when there is a procedure specifically designed to do the task as fast as possible.  

Astounding
PROC Star

The presence of an ID statement makes this a complex task for a DATA step.  It can be done, but requires a fair amount of macro processing ahead of time to identify the values of PARAM (which determine the names of the variables after transposing).  I agree with @RW9's conclusion ... better off using the procedure here.

vraj1
Quartz | Level 8

Reason being i have usubjid duplicates and i need all of them and it gets omited in proc transpose. attached is test data.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Then you have a more fundamental problem than wether to use a transpose or not.  Core concept of CDISC models is that each record is unique within its row.  If you cannot identify a unique record from the data you need to add another category to the SDTM so that you can identify unique records, or have columns for the data that applies to the unique record of data. 

In the case you provide (and I would recommend posting test data in the form of a datastep - i.e. test data, and as a datastep in the {i} code window, just a couple of rows is fine, not actual study data!), What I think your looking for is a summation of the discontinuation reasons across a subject, which I suppose looks like a transpose.  I would do it this way:

data want (keep=usubjid reasons);
  set have;
  by usubjid;  /* assumes sorted */
  retain reasons;
  length reasons $2000;
  if first.usubjid then reasons=dsterm;
  else reasons=catx(',',reasons,dsterm);
  if last.usubjid then output;
run;

This will add each reason to the reatined variable and on the last record for a subject output, so you have one row per subject with all the reasons in one field, which can then be merged onto your other data.

Tom
Super User Tom
Super User

Can you show what you want to get? Please reduce your data to just enough columns and rows to demonstrate the issue and post it into the question using the Insert SAS code icon.  So both input and output data. Make sure to include a problem case that has duplicate rows and be clear about how you want it handled.

 

You also seems to be using the wrong variable for the ID. PARAMCD looks more like a variable name than PARAM which looks like a sentence in your data.

 

If your ID variables are not enough to uniquely identify rows then you need to add another variable.  So you might add a sequence number for each distinct value of UNIQUEID, PARAM.

proc sort data=adds out=fixed_adds ;
  by usubjid paramcd;
run;
data fixed_adds ;
  by unsubjid paramcd;
  seq+1;
  if first.paramcd then seq=1;
run;

proc transpose data=fixed_adds out=trans_adds ;
by usubjid ;
id paramcd seq;
var avalc;
run;

Then you will get variables like PRIMREAS1, PRIMREAS2 and SECREAS1, SECREAS2, ...

Reeza
Super User

@vraj1 There is no test data attached?

 


@vraj1 wrote:

Reason being i have usubjid duplicates and i need all of them and it gets omited in proc transpose. attached is test data.

 


 

art297
Opal | Level 21

I agree with @Tom other than I presume you will always have a primary reason and, sometimes, secondary reason(s).

 

If so, you might be able to use something as simple as:

proc transpose data=adds out=trans_adds prefix=reasons_for_withdrawal;
  by usubjid ;
  var avalc;
run;

Art, CEO, AnalystFinder.com

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 8 replies
  • 995 views
  • 0 likes
  • 7 in conversation