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

Hello,

I would appreciate if someone could help me with the SAS code to count the number of subjects) not exposed to any of the the 4 agents (a1, a2,a3 and a4 ) below. Exposed is 1 and unexposed is zero (0).         From the dataset, ids os3, os6, os7 and os9 are unexposed to any of the agents so the freq should be 4. I don't  know if my approach is ok. In the results, I have controlling for a1=0 and a2=0. Does anyone has a better approach to this please? My code and log are found below; results are attached.

Thank you.

ak.

data agents_exp;
input id$ a1 a2 a3 a4;
datalines;
os1 1 0 0 1
os2 1 1 0 0
os3 0 0 0 0
os5 1 0 0 1
os6 0 0 0 0
os7 0 0 0 0
os8 1 0 1 1
os9 0 0 0 0
;
run;
proc print;

data a;
set agents_exp;
if a1 ne 0 then delete;
else if a2 ne 0 then delete;
else if a3 ne 0 then delete;
else if a4 ne 0 then delete;
run;


proc freq data=a;
tables a1*a2*a3*a4;
run;

OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data agents_exp;
74 input id$ a1 a2 a3 a4;
75 datalines;
 
NOTE: The data set WORK.AGENTS_EXP has 8 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
 
 
84 ;
85 run;
86 proc print;
87
 
NOTE: There were 8 observations read from the data set WORK.AGENTS_EXP.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.19 seconds
cpu time 0.20 seconds
 
 
88 data a;
89 set agents_exp;
90 if a1 ne 0 then delete;
91 else if a2 ne 0 then delete;
92 else if a3 ne 0 then delete;
93 else if a4 ne 0 then delete;
94 run;
 
NOTE: There were 8 observations read from the data set WORK.AGENTS_EXP.
NOTE: The data set WORK.A has 4 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds
 
 
95
96
97 proc freq data=a;
98 tables a1*a2*a3*a4;
99 run;
 
NOTE: There were 4 observations read from the data set WORK.A.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.17 seconds
cpu time 0.16 seconds
 
 
100
101 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
113

 

           

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@novinosrin wrote:

 data agents_exp;
input id$ a1 a2 a3 a4;
datalines;
os1 1 0 0 1
os2 1 1 0 0
os3 0 0 0 0 
os5 1 0 0 1 
os6 0 0 0 0
os7 0 0 0 0
os8 1 0 1 1
os9 0 0 0 0
;
run;
proc print;

proc sql;
select count(*)
from agents_exp
where max(a1,a2,a3,a4)=0;
quit;

@ak2011 did not show any missing results for the 4 values. If some missings were possible (unknown exposure perhaps) and you want known "not exposed" I would suggest including an N=4 in the condition.

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

 data agents_exp;
input id$ a1 a2 a3 a4;
datalines;
os1 1 0 0 1
os2 1 1 0 0
os3 0 0 0 0 
os5 1 0 0 1 
os6 0 0 0 0
os7 0 0 0 0
os8 1 0 1 1
os9 0 0 0 0
;
run;
proc print;

proc sql;
select count(*)
from agents_exp
where max(a1,a2,a3,a4)=0;
quit;
ballardw
Super User

@novinosrin wrote:

 data agents_exp;
input id$ a1 a2 a3 a4;
datalines;
os1 1 0 0 1
os2 1 1 0 0
os3 0 0 0 0 
os5 1 0 0 1 
os6 0 0 0 0
os7 0 0 0 0
os8 1 0 1 1
os9 0 0 0 0
;
run;
proc print;

proc sql;
select count(*)
from agents_exp
where max(a1,a2,a3,a4)=0;
quit;

@ak2011 did not show any missing results for the 4 values. If some missings were possible (unknown exposure perhaps) and you want known "not exposed" I would suggest including an N=4 in the condition.

novinosrin
Tourmaline | Level 20

Yes Sir @ballardw . Very good observation. I agree

ballardw
Super User

We can also filter data at use with where clause like:

proc print data=agents_exp;
   where max(a1,a2,a3,a4) =0;
run;
ak2011
Fluorite | Level 6
Thanks very much! Is a very good method.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 5 replies
  • 1018 views
  • 1 like
  • 3 in conversation