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

Ayooo1_0-1670357461672.pngAyooo1_1-1670357473092.png

Ayooo1_3-1670357548085.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

 

 

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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.

Ayooo1
Obsidian | Level 7

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;

 

ballardw
Super User

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;

 

 

Ayooo1
Obsidian | Level 7

thank you. This helped a lot.

sas-innovate-2024.png

📢

ANNOUNCEMENT

The early bird rate has been extended! Register by March 18 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

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