I am merging 2 datas by treatment to calculate the percentage, the count and the percentage together. One has the frequency of sex by treatment and the other is just the treatment. When merged, the count of the female treatment changes to the count of the total treatment. What can be done?
Your pictures don't have label to tell what data set they represent.
I think that you may actually have two separate counts of interest as the proc freq code generates a variable named count but then you recount the number of levels of variables with your Proc sql. So you lose the original counts with that. Then the merge aggravates that by combing rows of data.
I am going to suggest that you look at the output from this and see if one (or both) of the tables have the values that you might be looking for. Not a data set, a report that people read.
proc tabulate data=Listing2; class sex exdstxt; table SEX*EXDSTXT Exdstxt , n colpctn; table Exdstxt*(sex all='all sexes'), n colpctn pctn; run;
I see no variable called "treatment" in your pictures.
Please post examples for your datasets in usable form (data steps with datalines, do not skip this!) and your code.
EXDSTXT represents treatment.
proc freq data=Listing2;
tables SEX*EXDSTXT /out=FreqST;
tables EXDSTXT/out=FreqT;
run;
proc sort data=FreqST;
by EXDSTXT SEX;
run;
proc sort data=FreqT;
by EXDSTXT;
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 Listing2_1;
merge FreqST(in=a) FreqT(in=b);
by EXDSTXT;
if a and b;
run;
Your pictures don't have label to tell what data set they represent.
I think that you may actually have two separate counts of interest as the proc freq code generates a variable named count but then you recount the number of levels of variables with your Proc sql. So you lose the original counts with that. Then the merge aggravates that by combing rows of data.
I am going to suggest that you look at the output from this and see if one (or both) of the tables have the values that you might be looking for. Not a data set, a report that people read.
proc tabulate data=Listing2; class sex exdstxt; table SEX*EXDSTXT Exdstxt , n colpctn; table Exdstxt*(sex all='all sexes'), n colpctn pctn; run;
thank you. This helped a lot.
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.