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 cases(ca case) and controls (pop cont) 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 would like the frequency to be split the frequence into ca case and pop cont. os3: pop cont, os6: ca case, o7: ca case and os9: ca case so in total there are 1 pop cont and 3 ca case (total 4 subjects) but I would like SAS to split the freq of 4 into their respective lung cancer type(ca case and pop cont). The output from attached table 2 is not correct. I need SAS to show and count only the unexposed subjects.

 Please, can anyone help me to with the SAS code to solve this problem? My code and log are found below; results are attached, but actually Table 2 is incorrect.

Thank you.

ak.

 

data agents_exp;
input id$ a1 a2 a3 a4 lung$ 13-20;
datalines;
os1 1 0 0 1 ca case
os2 1 1 0 0 ca case
os3 0 0 0 0 pop cont
os5 1 0 0 1 pop cont
os6 0 0 0 0 ca case


OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data agents_exp;
74 input id$ a1 a2 a3 a4 lung$ 13-20;
75 datalines;
 
NOTE: The data set WORK.AGENTS_EXP has 8 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
 
 
84 ;
85 run;
86 proc print data=agents_exp;
87 Title 'Table 1: Exposure of ids to 4 agents';
88
 
NOTE: There were 8 observations read from the data set WORK.AGENTS_EXP.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.23 seconds
cpu time 0.22 seconds
 
 
89 proc sql;
90 create table t as
91 select
92 id, a1, a2, a3,a4,lung,
93 sum(a1,a2,a3,a4)=0 as afinal
94 from agents_exp
95 ;
NOTE: Table WORK.T created, with 8 rows and 7 columns.
 
96 quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
 
 
97
98 proc freq data=t;
99 tables lung*afinal;
100 title 'Table 2: freq of ca case and pop cont for for unexposed agents';
101 run;
 
NOTE: There were 8 observations read from the data set WORK.T.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.21 seconds
cpu time 0.20 seconds
 
 
102
103 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
115

 


os7 0 0 0 0 ca case
os8 1 0 1 1 pop cont
os9 0 0 0 0 ca case
;
run;
proc print data=agents_exp;
Title 'Table 1: Exposure of ids to 4 agents';

proc sql;
create table t as
select
id, a1, a2, a3,a4,lung,
sum(a1,a2,a3,a4)=0 as afinal
from agents_exp
;
quit;

proc freq data=t;
tables lung*afinal;
title 'Table 2: freq of ca case and pop cont for for unexposed agents';
run;


 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
proc freq data=agents_exp(where=(sum(of a1-a4)=0)));
     table lung;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
proc freq data=agents_exp(where=(sum(of a1-a4)=0)));
     table lung;
run;
--
Paige Miller
ak2011
Fluorite | Level 6
Hi,
Thanks for your time. There were errors in the code so I modified it a bit before it worked:

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 proc freq data=agents_exp(where=(sum(of a1-a4)=0)));
__ _
22 200
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
CONTAINS, EQ, GE, GT, LE, LIKE, LT, NE, OR, ^=, |, ||, ~=.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 76-322: Syntax error, statement will be ignored.

73 ! proc freq data=agents_exp(where=(sum(of a1-a4)=0)));
_
22
ERROR: Syntax error while parsing WHERE clause.
ERROR 22-322: Syntax error, expecting one of the following: ;, COMPRESS, DATA, FC, FORMCHAR, NLEVELS, NOPRINT, ORDER, PAGE.
74 table lung;
75
76 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
88

I modified as:


1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 proc freq data=agents_exp(where=(sum(a1,a2,a3,a4)=0));
74 table lung;
75 run;

NOTE: There were 4 observations read from the data set WORK.AGENTS_EXP.
WHERE SUM(a1, a2, a3, a4)=0;
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.25 seconds
cpu time 0.24 seconds


76
77 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
89

Thanks.
ak.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2 replies
  • 635 views
  • 0 likes
  • 2 in conversation