BookmarkSubscribeRSS Feed
saslove
Quartz | Level 8

I need to combine reasons from my dataset to look like these for the ones in the table that have a reason/cause. I have completed the programming part to create the table, but I don't know how to append the reason/cause to the code.

 


proc sql;
create table table as

select distinct
1 as no,
'Enrolled' as descrip,
put(count(case when enrolled=1 then 1 else . end),2.) as count
from enrolled

union
select distinct
2 as no,
'Treated' as descrip,
put(count(case when treated=1 then 1 else . end),2.) as count
from treated

union
select distinct
3 as no,
'Off-study prior to receiving therapy' as descrip,
put(count(case when offstudy_pre_trt=1 then 1 else . end),2.) as count
from offstudy_pre_trt

union
select distinct
4 as no,
'On-study, Active' as descrip,
put(count(case when off_study=0 then 1 else . end),2.) as count
from on_study

union
select distinct
5 as no,
'On-study, LTFU' as descrip,
put(count(case when ltfu=1 then 1 else . end),2.) as count
from ltfu

union
select distinct
6 as no,
'Deaths on study and cause of death' as descrip,
put(count(case when death_onstudy=1 then 1 else . end),2.) as count
from on_study

union
select distinct
7 as no,
'Off-study and reason' as descrip,
put(count(case when off_study=1 then 1 else . end),2.) as count
from on_study

order by no;
quit;

 

For #6 and #7, please tell me how to append the associated reason.

 

Thanks,

 

This is how the table should look:

Category

Number of Subjects

Enrolled

abc

Treated

abc with 1 retreatment

Off-study prior to receiving therapy

a

On study, active

b

On study, LTFU

aaa

Deaths while on study and cause of death

xx due to Progressive Disease

cy due to Transplant Complications

Off-study and reason

ab due to death

6 due to did not receive CAR T cells

6 REPLIES 6
Reeza
Super User

 

catx( ' - ' ,
       put(count(case when off_study=1 then 1 else . end),2.),
       reason _text)
 as count

Change your last variable to be something like above, basically use CATX to append the data? Where does the 'reason' come from? I'm assuming it's in your data set somewhere.

 


@saslove wrote:

I need to combine reasons from my dataset to look like these for the ones in the table that have a reason/cause. I have completed the programming part to create the table, but I don't know how to append the reason/cause to the code.

 


proc sql;
create table table as

select distinct
1 as no,
'Enrolled' as descrip,
put(count(case when enrolled=1 then 1 else . end),2.) as count
from enrolled

union
select distinct
2 as no,
'Treated' as descrip,
put(count(case when treated=1 then 1 else . end),2.) as count
from treated

union
select distinct
3 as no,
'Off-study prior to receiving therapy' as descrip,
put(count(case when offstudy_pre_trt=1 then 1 else . end),2.) as count
from offstudy_pre_trt

union
select distinct
4 as no,
'On-study, Active' as descrip,
put(count(case when off_study=0 then 1 else . end),2.) as count
from on_study

union
select distinct
5 as no,
'On-study, LTFU' as descrip,
put(count(case when ltfu=1 then 1 else . end),2.) as count
from ltfu

union
select distinct
6 as no,
'Deaths on study and cause of death' as descrip,
put(count(case when death_onstudy=1 then 1 else . end),2.) as count
from on_study

union
select distinct
7 as no,
'Off-study and reason' as descrip,
put(count(case when off_study=1 then 1 else . end),2.) as count
from on_study

order by no;
quit;

 

For #6 and #7, please tell me how to append the associated reason.

 

Thanks,

 

This is how the table should look:

Category

Number of Subjects

Enrolled

abc

Treated

abc with 1 retreatment

Off-study prior to receiving therapy

a

On study, active

b

On study, LTFU

aaa

Deaths while on study and cause of death

xx due to Progressive Disease

cy due to Transplant Complications

Off-study and reason

ab due to death

6 due to did not receive CAR T cells


 

saslove
Quartz | Level 8

It kinda worked but that row is repeated for every single reason. I want count due to reason , count due to reason, count due to reason. (separated by comma).

 

Please see attached.. 

 

 

 

Reeza
Super User
No attachment was included. CATX() is the function you need to concatenate text comments, so you'll likely want to nest it a bit. I suspect a data step would be a lot easier for this.
saslove
Quartz | Level 8

I am attaching once again.. 

 

In a datastep, how can I get the n and also concatenate separated by a comma on the same row.

 

Capture.PNG

Reeza
Super User
AFAIK you cannot easily do that in SQL. You’ll have to change to a data step.
saslove
Quartz | Level 8
Ok just an update on what I did.
I used proc freq and did a 2x2 to output the flags and reasons . I used data step to concatenate.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1760 views
  • 0 likes
  • 2 in conversation