BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

In the ouput result of the below program (in the grey box), I need to have zero count(NS=0) when there are no subjects present for the treatment.

 

Output needed:

NS TRT

2    30mg

3    45mg 

1     placebo

0     15mg

 

output getting

NS TRT

2    30mg

3    45mg 

1     placebo

 

data one;
input id trt$ sflag$;
datalines;
1 45mg Y 
2 30mg Y
3 15mg N
4 30mg Y
5 45mg Y
6 plcebo Y
7 45mg Y
;
PROC SQL;
create table two as 
select count(distinct id) as NS,trt
from one
where sflag='Y'
group by trt;
quit;

 

I think I can get the output by  two proc transpose and two datsteps inbetween. But please suggest me if any better way to do this. Thank you very much

 

program I am running to get output I need

 

proc transpose data=two out=three(drop=_NAME_);
var NS;
id TRT;
run;


data four;
set three;
array data _15mg _30mg _45mg placebo;
do over data;
if missing(data) then data=0;
end;
TOTAL=_15mg + _30mg + _45mg ;
run;

 

proc transpose data=four out=five;
var placebo _15mg _30mg _45mg total ;
run;

 

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

It can be done simpler. But what if your data looked like this? 

 

data one;
input id trt$ sflag$;
datalines;
1 45mg Y 
2 30mg Y
3 15mg N
4 30mg Y
5 45mg Y
6 plcebo Y
7 45mg Y
8 15mg Y
;

So that you also had a 15mg observation with sflag='Y'. What would your desired output look like then?

knveraraju91
Barite | Level 11

Then my output is

 

NS TRT

2    30mg

3    45mg 

1     placebo

1     15mg

 

Thank you

s_lassen
Meteorite | Level 14

I would probably try something like

proc sql;
  create table want as
  select trt,sum(sflag='Y')
  from have
group by trt; quit;

 

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