HI,
I have large datset and have to produce the counts . I am able to create the counts through proc freq but then I am unable to put them at single place or ouptput.For example : I provideone of the desired output as shown below. The purpose is to put individualoutputs produced through proc freq at one place not to produce exactly the same style of table as given here .
| N |
|
| N |
|
| N |
Farm1
| 4 | Meat1 | « 0 » | 0 | Facility1 | <0 | 1 |
<100 | 1 | ||||||
« 1 » | 4 | <50 | 2 | ||||
Farm2
| 4 | Meat2 | « 0 » | 1 | Facility2 | <0 | 2 |
« 1 » | 3 | <50 | 2 |
Any help is higly appreciated.
Thanks once again,
DATA have;
input Meat1 Meat2 Meat3 Meat4 Meat5 Farm1$ Farm2$ Farm3$ Farm4$ Farm5$ Facility1$ Facility2$ Facility3$ Facility4$ Facility5$;
Datalines;
1 1 0 1 0 Y Y Y N Y <100 <0 <50 <100 <100
1 1 1 1 0 Y Y Y N Y <50 <50 <100 <0 <100
1 1 1 1 0 Y Y Y N Y <0 <0 <50 <0 <100
1 1 1 0 0 Y N Y Y N <50 <50 <0 <100 <100
0 0 1 0 0 N Y Y N N <50 <50 <100 <50 <50
;
run;
%macro freq();
%do i=1 %to 5;
proc freq data=have;
tables Farm&i meat&i Facility&i/ nocum nopercent;
run;
%end;
%mend;
%freq();
DATA have; input Meat1 Meat2 Meat3 Meat4 Meat5 Farm1$ Farm2$ Farm3$ Farm4$ Farm5$ Facility1$ Facility2$ Facility3$ Facility4$ Facility5$; Datalines; 1 1 0 1 0 Y Y Y N Y <100 <0 <50 <100 <100 1 1 1 1 0 Y Y Y N Y <50 <50 <100 <0 <100 1 1 1 1 0 Y Y Y N Y <0 <0 <50 <0 <100 1 1 1 0 0 Y N Y Y N <50 <50 <0 <100 <100 0 0 1 0 0 N Y Y N N <50 <50 <100 <50 <50 ; run; %macro data; proc sql noprint; %do i=1 %to 5; create table a&i as select "Farm&i" as var1 length=10 label=' ',count(*) as n1 label='N' from have ; create table b&i as select "Meat&i" as var2 length=10 label=' ',meat&i label=' ' as meat,count(*) as n2 label='N' from have group by meat&i ; create table c&i as select "Facility&i" as var3 length=10 label=' ',Facility&i label=' ' as facility,count(*) as n3 label='N' from have group by Facility&i ; %end; quit; %do j=1 %to 5; data x&j; merge a&j b&j c&j; output; call missing(of _all_); run; %end; data x; set x1-x5; run; %mend data; %data options missing=' '; proc report data=x nowd;run;
Ksharp
DATA have; input Meat1 Meat2 Meat3 Meat4 Meat5 Farm1$ Farm2$ Farm3$ Farm4$ Farm5$ Facility1$ Facility2$ Facility3$ Facility4$ Facility5$; Datalines; 1 1 0 1 0 Y Y Y N Y <100 <0 <50 <100 <100 1 1 1 1 0 Y Y Y N Y <50 <50 <100 <0 <100 1 1 1 1 0 Y Y Y N Y <0 <0 <50 <0 <100 1 1 1 0 0 Y N Y Y N <50 <50 <0 <100 <100 0 0 1 0 0 N Y Y N N <50 <50 <100 <50 <50 ; run; %macro data; proc sql noprint; %do i=1 %to 5; create table a&i as select "Farm&i" as var1 length=10 label=' ',count(*) as n1 label='N' from have ; create table b&i as select "Meat&i" as var2 length=10 label=' ',meat&i label=' ' as meat,count(*) as n2 label='N' from have group by meat&i ; create table c&i as select "Facility&i" as var3 length=10 label=' ',Facility&i label=' ' as facility,count(*) as n3 label='N' from have group by Facility&i ; %end; quit; %do j=1 %to 5; data x&j; merge a&j b&j c&j; output; call missing(of _all_); run; %end; data x; set x1-x5; run; %mend data; %data options missing=' '; proc report data=x nowd;run;
Ksharp
Thank you very much,Ksharp. It really helped.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.