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

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.

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