BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tsureshinvites
Obsidian | Level 7
I am not aware how to gourp the observations.

I am new to clinical SAS, need help of for the below queries.

 

Raw Data;

 

input id$ Visit $ Date $

datalines;

 

Raw Data 
IDVistStart Date
B1110001Baseline4/18/2016
B1110001Visit4/19/2016
B1110003Baseline4/18/2016
B1110003Visit 14/20/2016
B1110004Baseline4/18/2016
B1110004VISIT 14/19/2016
B1110004VISIT 24/21/2016

 

 

Need outup;

 

Output 
IDVistStart DateEnd Date
B1110001Visit Group A4/18/20164/19/2016
B1110003Visit Group A4/18/20164/20/2016
B1110004Visit Group B4/18/20164/21/2016

 

Notes;

 

1.  want to sort same ID and make as one group.

2. assign start date as first visit date.

3. assign end date as last visit date.

 

 

sample code;

data want;

set sashelp.class

Please help me.

1 ACCEPTED SOLUTION

Accepted Solutions
jvdl
Obsidian | Level 7

Piggybacking on the datalines provided by Jag above, you could also try something like the following, but I am also unsure how you determine whether it's visit group "A" or "B".

 

data have;
input ID$	Vist$	Start_Date$10.;
cards;
B1110001 Baseline 4/18/2016
B1110001 Visit 4/19/2016
B1110003 Baseline 4/18/2016
B1110003 Visit1 4/20/2016
B1110004 Baseline 4/18/2016
B1110004 VISIT1 4/19/2016
B1110004 VISIT2 4/21/2016
;

proc sql noprint;
	create table want as
		select distinct ID, "Visit Group ?" as visit, min(start_date) as start_date, max(start_date) as end_date
		from have
		group by id
		order by id
	;
quit;

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

How is Visit Group A / Visit Group B determined?

tsureshinvites
Obsidian | Level 7

attached file shot for your reference,

 

in that visit of "baseline"  , "c1w1" considered as double-blind treatment. (ie group A)

Visit of "c1w2" considered as open label treatment (ie group B)

so i want to group of (group A and Group B observation as)  epoch as "Treatment".

 

 

Jagadishkatam
Amethyst | Level 16

you can try something like below

 

data have;
input ID$	Vist$	Start_Date$10.;
cards;
B1110001 Baseline 4/18/2016
B1110001 Visit 4/19/2016
B1110003 Baseline 4/18/2016
B1110003 Visit1 4/20/2016
B1110004 Baseline 4/18/2016
B1110004 VISIT1 4/19/2016
B1110004 VISIT2 4/21/2016
;

data want;
length start end $10.;
set have;
retain start;
by id;
if first.id then start=Start_Date;
if last.id then end=Start_Date;
if last.id;
drop Start_Date;
run;
Thanks,
Jag
jvdl
Obsidian | Level 7

Piggybacking on the datalines provided by Jag above, you could also try something like the following, but I am also unsure how you determine whether it's visit group "A" or "B".

 

data have;
input ID$	Vist$	Start_Date$10.;
cards;
B1110001 Baseline 4/18/2016
B1110001 Visit 4/19/2016
B1110003 Baseline 4/18/2016
B1110003 Visit1 4/20/2016
B1110004 Baseline 4/18/2016
B1110004 VISIT1 4/19/2016
B1110004 VISIT2 4/21/2016
;

proc sql noprint;
	create table want as
		select distinct ID, "Visit Group ?" as visit, min(start_date) as start_date, max(start_date) as end_date
		from have
		group by id
		order by id
	;
quit;
tsureshinvites
Obsidian | Level 7

Thanks a lot. your simple code made wonderful output.

ballardw
Super User

Please do not post a question in terms different than your "data". Your spreadsheet does not use "Visit Number", so you really need to provide significant detail on how to use the values C1W1 and such that do appear.

 

It appears that possibly your first step would be to sort the data by subjid date and visit.

 

Then describe what the desired output should be subjects with no visit other than Baseline. Or if Visits other than Baseline include both C1W1 and C1W2 (or other combinations if possible).

 

From your example data it appears that you have some subjid that do not have a BASELINE entry, only the C1W2. So what do you expect the output for those to look like?

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 6 replies
  • 1475 views
  • 1 like
  • 5 in conversation