I'm fairly new at this and ran into a problem with proc freq. An practice task says I need to proc freq a merged dataset by sex*treatment and get the count for each gender by treatment and by treatment and get the count by treatment. I'm not too sure about how to get the count. Is what I'm doing correct?
example data:
data Listing;
merge Ex Dm;
by SUBJID
;
run;
proc freq data=Listing;
tables SEX*EXDSTXT/out=FreqST;
tables EXDSTXT/out=FreqT;
run;
proc sql;
select SEX, EXDSTXT, count(*) as Count
from FreqST
group by SEX,EXDSTXT;
select EXDSTXT, count (*) as Count
from FreqT
group by EXDSTXT;
quit;
data Listing;
merge Ex Dm;
by SUBJID
;
run;
proc freq data=Listing;
tables SEX*EXDSTXT/out=FreqST;
tables EXDSTXT/out=FreqT;
run;
proc sql;
select SEX, EXDSTXT, count(*) as Count
from FreqST
group by SEX,EXDSTXT;
select EXDSTXT, count (*) as Count
from FreqT
group by EXDSTXT;
quit;
@Ayooo1 wrote:
Is what I'm doing correct?
Do you get the right answer when you run the code? Do you get errors in the log when you run the code?
the code runs but does not give the right count.
Show us. Also, please provide data not in an attachment, but as SAS code pasted into the window that appears when you click on the "little running man" icon.
This is my task:
1. Assigned dose variable can be used as treatment group.
2. Retrieve the initial dose(the first dosage of the subject, sorted by subjid and dose)
hint:
Proc sort; by subjid dose; run;
Data xxx;
set xxx;
by subjid dose;
If first.subjid;
run;
3. merge with sex variable from dm by subjid
4. Proc freq by sex*treatment and get the count for each gender by treatment
5. Proc freq by treatment and get the count by treatment
6. Merge 5 and 6 by treatment and calculate the percentage and concatenate count and percentage together.
7. Proc transpose to form se frequency block like table shell.
proc sort data=Sasfile.Ex;
by SUBJID EXDSTXT;
run;
data Ex;
set Sasfile.Ex;
by SUBJID EXDSTXT;
keep SUBJID EXDSTXT;
if first.SUBJID;
run;
data Dm;
set Sasfile.Dm;
keep SUBJID SEX;
if SEX="M" then SEX="Male";else SEX="Female";
run;
proc sort data=Dm;
by SUBJID;
run;
data Listing2;
merge Ex Dm;
by SUBJID;
run;
proc freq data=Listing2;
tables SEX*EXDSTXT /out=FreqST;
tables EXDSTXT/out=FreqT;
run;
proc sql;
select SEX, EXDSTXT, count(*) as Count
from FreqST
group by SEX,EXDSTXT;
select EXDSTXT, count (*) as Count
from FreqT
group by EXDSTXT;
quit;
So what is wrong here? You said the results are wrong ... show us the results and explain what is wrong. Show us data sets FREQST and FREQT.
Never mind. I figured it out. Thank you for helping.
Please update your post as answered in that case.
@Ayooo1 Please provide the answer so that other can learn.
answer is as is in the original post. I just got confused.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.