BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nkm123
Calcite | Level 5

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,

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

5 REPLIES 5
Tom
Super User Tom
Super User

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;
Reeza
Super User

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.

nkm123
Calcite | Level 5

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.

Reeza
Super User

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. 

 

 

 

Ksharp
Super User

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


sas-innovate-2024.png

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.

 

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
  • 5 replies
  • 7271 views
  • 0 likes
  • 4 in conversation