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

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