DATA Step, Macro, Functions and more

Proc Freq with multiple dataset

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

Proc Freq with multiple dataset

[ Edited ]

Is there any option to define multiple dataset in proc freq data = ? statement.

 

Ex:- Suppose I have three dataset data1 , data2, data3 and have variable called sales_date (common in all three dataset). I want to have freq of sales_date on all three dataset.

 

Instead of writing a macro, do we have any option like :

 

- proc freq data = data1 data2 data3 ; tables sales_date/list missing;run;

 

macro solution:-

 

%macro freq(indsn,var_name);

Proc frea data = &indsn.;

tables &var_name./list missing;

run;

%mend;

 

%freq(data1,sales_date);

%freq(data2,sales_date);

 %freq(data3,sales_date);

 

2) and is there any way to compare freq of sales_date across all three dataset without mergeing or creating new dataset with rename of sales_date. by variable could be store_id and want to compare sales_date across all thre dataset. store_id is unique.

 

proc freq data = mergedataset;  (mergerdataset is merge of data1,data2, data3 on store_id and rename sales_date to sales_date1,2,3)

tables sales_date1*sales_date2*sales_date3/list misisng;

run;

 

so instead of above , is there any shortcut to compare it .

 

Thanks,

 

 


Accepted Solutions
Solution
‎04-01-2016 10:44 PM
Super User
Super User
Posts: 7,074

Re: Proc Freq with multiple dataset

In general NO.

It is not hard to combine the data into a single table and then run the FREQS.

data want ;
   length indsname source $41;
   set data1-data3 indsname=indsname ;
   source=indsname;
run;
proc freq data=want ;
  tables sales_date*source / list missing;
run;

View solution in original post


All Replies
Solution
‎04-01-2016 10:44 PM
Super User
Super User
Posts: 7,074

Re: Proc Freq with multiple dataset

In general NO.

It is not hard to combine the data into a single table and then run the FREQS.

data want ;
   length indsname source $41;
   set data1-data3 indsname=indsname ;
   source=indsname;
run;
proc freq data=want ;
  tables sales_date*source / list missing;
run;
Super User
Posts: 19,855

Re: Proc Freq with multiple dataset

Not really, but you can create a view so it only combines when you need it. 

 

data combined /view=combined;
set data1 data2 data3;
run;

proc freq data=combined;
tables sales_date/missing;
run;

It makes sense to not allow this, as SAS would then have to also verify that data structures were the same and that it was valid to combine the data sets in each proc, which just adds overhead.

Contributor
Posts: 30

Re: Proc Freq with multiple dataset

Thanks for quick replay. How to compare sales_date across all dataset. all datasets have same number of observation (soppose 1000 obs) and common unique variable is store_id.

Super User
Posts: 19,855

Re: Proc Freq with multiple dataset

That depends what you want, I'm not 100% clear on that.

 

If you need a merge then you could also create a view that did that, but you would have to rename the columns.  

It might be easier at that point to write a sql query that did the join and comparison in one. 

 

 

 

Super User
Posts: 10,041

Re: Proc Freq with multiple dataset


In general YES.
But you need proc sql instead of proc freq.


☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 788 views
  • 0 likes
  • 4 in conversation