/* Sort the Products dataset by review_count in descending order */
proc sort data=Qed.Products;
by descending review_count;
/* Print the top-most record (most reviewed product) */
if _N_ = 1;
/* Print the most reviewed product */
PROC PRINT DATA=MostReviewedProduct;
TITLE "Most Reviewed Product";
/* Sort the Products dataset by review_count in ascending order */
proc sort data=Qed.Products;
/* Print the top-most record (least reviewed product) */
if _N_ = 1;
/* Print the least reviewed product */
PROC PRINT DATA=LeastReviewedProduct;
TITLE "Least Reviewed Product";
/* Compare the most reviewed and least reviewed products */
merge MostReviewedProduct (in=a) LeastReviewedProduct (in=b);
if a and b then do;
if review_count_1 < review_count_2 then do;
message = "Most reviewed product has fewer reviews than the least reviewed product.";
else if review_count_1 > review_count_2 then do;
message = "Most reviewed product has more reviews than the least reviewed product.";
message = "Most reviewed product has the same number of reviews as the least reviewed product.";
/* Print the comparison result */
PROC PRINT DATA=ProductComparison;
var review_count_1 review_count_2 message;
title "Comparison Between Most Reviewed and Least Reviewed Products";
HI THIS IS MY CODE AND THE COMPARISON TABLE IS EMPTY
We would need to see the entire LOG (copied as text and pasted into the window that appears when you click on the </> icon) and also we need to see a portion of your data. Please provide the data as WORKING data step code (Examples and instructions)
data ProductComparison; merge MostReviewedProduct (in=a) LeastReviewedProduct (in=b); by _all_; if a and b then do;
When you merge two data sets, they have the same variable names. SAS will overwrite the variables so you don't have two counts you only have one.
Run just this portion to see what you get before you start doing your analysis.
You need to fix the merge before you do the remainder of the process, primarily by renaming variables of interest or using an append (SET) and reference variables using lag instead.
When you ask "why" we need either the data files used, which may have problems with sharing, and the log of the step you question. So go to the log where you get the empty table, copy the CODE and all notes or messages from that step. Then on the forum open a text box using the </> icon above the message window and paste the text.
Most likely cause from the code I see is that since you use BY _ALL_ in the Merge then one or more variables does not have the same value in both sets. In fact since you sorted and sub-setted the data on Review_count variable values I would be extremely surprised if the "most reviewed" and "least reviewed" have the same number of reviews. So they would not merge onto the same observation.
Pick actual identifying variables for a BY. Do not include variables like "counts" unless you expect most of them to match. And if you have two different variables for the count, implied but not shown, then don't expect them to match very often.
Something else, you may want to rename the Review_count variable from one or both of the sets so that you have two variables to actually compare. I do not see where Review_count_1 or Review_count_2 are assigned/created from I have to assume from Review_count in Qed.Products.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.
Find more tutorials on the SAS Users YouTube channel.