BookmarkSubscribeRSS Feed
jinbei
Calcite | Level 5

Hi all; I want to know if there is another better way to add the group number easily,when using  the PROC FREQ procedure to caculate the P value.

The column A &column B in attachment is what i want to generate,the two columns are not included in the data set 'mergeorder'.
the want dataset is like this:
 cate                   trt             COUNT         total           A           B
xxxx                   GL              xx                 xx              1            1
xxxx                   GL              xx                 xx              1            2
xxxx                   LY               xx                xx               2            1
xxxx                   LY               xx                xx               2            2
..............
the data set 'mergeorder'. has too many categories ,there are only two trt groups (GL &LY),each trt group has been caculated by 'total-count' .
Here is my approach ,
 
data fish;
set mergeorder;
IF TRT='GL'
THEN DO
A=1;
B=1;
OUTPUT;
END;
IF TRT='LY' THEN DO
A=2 ;
B=1;
OUTPUT;
END;
run;
data fish2;
set merge2;
COUNT=TOTAL-COUNT;OUTPUT;
run;
DATA FISH3;
SET FISH2;
IF TRT='GL'
THEN DO
A=1;
B=2;
OUTPUT;
END;
IF TRT='LY' THEN DO
A=2 ;
B=2;
OUTPUT;
END;
RUN;
DATA FISHER;
SET FISH FISH3;
RUN;
PROC SORT DATA=FISHER out=fishorder;
BY CATE;
RUN;
proc freq data=fishorder   ;
table a*b /  fisher ;
weight count/zeros;
by cate;
output out=fish_2 fisher;
run;
 
Thanks!
1 REPLY 1
Astounding
PROC Star

If I understand correctly, you're starting with the data set you have shown, minus the A and B columns.  Depending on what they are supposed to contain (you really have shown just an abbreviated version), here is one way to add them:

 

data want;

set have;

by trt notsorted;

if first.trt then do;

   A + 1;

   B = 1;

end;

else B + 1;

run;

 

Even if this isn't the right result, you will probably need some variation on these tools to get what you want.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 756 views
  • 0 likes
  • 2 in conversation