BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ayooo1
Obsidian | Level 7

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:

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ayooo1
Obsidian | Level 7

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;

View solution in original post

10 REPLIES 10
Ayooo1
Obsidian | Level 7

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;

PaigeMiller
Diamond | Level 26

@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?

--
Paige Miller
Ayooo1
Obsidian | Level 7

the code runs but does not give the right count.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Ayooo1
Obsidian | Level 7

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;

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Ayooo1
Obsidian | Level 7

Never mind. I figured it out. Thank you for helping.

SASKiwi
PROC Star

Please update your post as answered in that case.

PaigeMiller
Diamond | Level 26

@Ayooo1 Please provide the answer so that other can learn.

--
Paige Miller
Ayooo1
Obsidian | Level 7

answer is as is in the original post. I just got confused.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

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.

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