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

Hi guys,

i got the next records:

subjid phase  fdosedt         ldosedt         

x-1      ol     28sep03       14dec03           

x-2      db    28sep03        14dec03          

x-2      ol     26sep06        12dec06          

I would like to get something like that:

subjid    fdosedt_db ldosedt_db fdosedt_ol     ldosedt_ol     

           

x-1                                          28sep03       14dec03             

x-2        28sep03   14dec03      26sep06        12dec06

any help?

Thanks in advance.

J.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

How about

data have;
input subjid $ phase  $ fdosedt  :date9.       ldosedt   :date9.;  
format fdosedt   ldosedt date9.;
cards;
x-1      ol     28sep03       14dec03           
x-2      db    28sep03        14dec03          
x-2      ol     26sep06        12dec06      
;
run;
proc sql noprint;
 select distinct catt('have(where=(phase="',phase,'") rename=(fdosedt=fdosedt_',phase,' ldosedt=ldosedt_',phase,'))')  
  into : list separated by ' '
   from have;
quit;
data want(drop=phase);
 merge &list ;
 by subjid;
run;

Ksharp

View solution in original post

4 REPLIES 4
Ksharp
Super User

How about

data have;
input subjid $ phase  $ fdosedt  :date9.       ldosedt   :date9.;  
format fdosedt   ldosedt date9.;
cards;
x-1      ol     28sep03       14dec03           
x-2      db    28sep03        14dec03          
x-2      ol     26sep06        12dec06      
;
run;
proc sql noprint;
 select distinct catt('have(where=(phase="',phase,'") rename=(fdosedt=fdosedt_',phase,' ldosedt=ldosedt_',phase,'))')  
  into : list separated by ' '
   from have;
quit;
data want(drop=phase);
 merge &list ;
 by subjid;
run;

Ksharp

michtka
Fluorite | Level 6

It works.

Thanks Ksharp.

Could you write down the code not using the  sql procedure too?

Thanks in advance.

Ksharp
Super User

OK. no problem.

data have;
input subjid $ phase  $ fdosedt  :date9.       ldosedt   :date9.;  
format fdosedt   ldosedt date9.;
cards;
x-1      ol     28sep03       14dec03           
x-2      db    28sep03        14dec03          
x-2      ol     26sep06        12dec06      
;
run;
proc sort data=have(keep=phase) out=temp nodupkey;by phase;run;
data _null_;
 set temp end=last;
 if _n_ eq 1 then call execute('data want(drop=phase);merge ');
  call execute(catt('have(where=(phase="',phase,'") rename=(fdosedt=fdosedt_',phase,' ldosedt=ldosedt_',phase,'))'));
 if last then call execute(';by subjid;run;');
run;

Ksharp

Learner_SAS
Calcite | Level 5

It can be done using proc transpose too.

proc transpose data=have out=dummy;
by subjid phase ;
var ldosedt fdosedt ;
run;

data dummy;
set dummy;
VAR=catx('_',_name_,phase);
run;

proc transpose data=DUMMY out=WANT (drop=_NAME_);
by subjid;
id VAR;
run;

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!

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
  • 654 views
  • 0 likes
  • 3 in conversation