Help using Base SAS procedures

combinign proc freq output results

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

combinign proc freq output results

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();


Accepted Solutions
Solution
‎11-24-2011 03:02 AM
Super User
Posts: 10,023

combinign proc freq output results

Posted in reply to Swordfish
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

View solution in original post


All Replies
Solution
‎11-24-2011 03:02 AM
Super User
Posts: 10,023

combinign proc freq output results

Posted in reply to Swordfish
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

Occasional Contributor
Posts: 18

combinign proc freq output results

Thank you very much,Ksharp. It really  helped.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 124 views
  • 0 likes
  • 2 in conversation