BookmarkSubscribeRSS Feed
js5
Pyrite | Level 9 js5
Pyrite | Level 9

Hello,

 

I have the following code:

proc freq data=inputds noprint;
	by notsorted a b c;
	tables x*y*z/out=freq;
	weight count/zeros;
run;

proc means data=inputds completetypes noprint nway;
	by notsorted a b c;
	var count;
	output out=means(drop=_:) sum=count_sum_c;
run;

data final;
	merge freq means;
	by notsorted a b c;
run;

Is it possible to produce the dataset in one single step? having a notsorted means that the merge is not possible, and due to the fact that the input and freq datasets contain over 90 million rows, I would prefer not to have to sort anything unless absolutely unavoidable. Thank you for your tips in advance.

2 REPLIES 2
Tom
Super User Tom
Super User

Without data or even a description of what you are trying to do it is going to be hard.

 

Why not just let PROC MEANS add up the WEIGHT variable for you (especially since you want to include the zero weight observations)?

proc means data=inputds completetypes noprint nway;
  class a b c;
  output out=means(drop=_:) n=nobs sum(count)=count_sum_c;
run;
ballardw
Super User

You might describe what you are wanting as output and do you actually need a data set? If the data set is not used for anything other than reporting it may be that a report procedure is the way to go.

And providing data in the form of a working data step usually helps.

Provide a subset and what you expect as a final result for that subset of data.

 

I am a bit concerned that you may not be getting what you want as output to begin with by using not sorted.

 

IF two data sets have the same number of observations you might try as without a BY then SAS does a line by line merge regardless of values. The output of the two data sets may be in the same order because of the way SAS process notsorted data.

data final;
	merge freq means;
run;

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

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.

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
  • 2 replies
  • 125 views
  • 0 likes
  • 3 in conversation