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

I have a data set of 434 observation (named as selection) and another data-set with about 17000 observations (named as nodup). The first data-set is my main analysis group (study group) and I want to select one control match from the second data-set for each of the observations in the study group. The matching variables are SIC, FYEAR, SALE. the first two should be exact matches, while SALE should be between a range, defined by lowsale and highsale variables.

If I run this PROC SQL, I will get multiple matches for some of the observation in my study group, while for some others, there is only one match.

proc sql;

create table controls_id as

select * from selection, nodup

where ((nodup.xSALE between selection.lowsale and selection.highsale) and

and selection.SIC=nodup.xsic

and selection.fyear=nodup.xfyear );

quit;

When I have multiple matches, I want to select the closest match for my observation. the closeness is defined as ((sale-xsale)^2). In other words, I want to select the match which has the smallest difference in the sale variable.

Would you please let me know how I can perform this step?

Thanks for reading this post

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

Create the closiness column, and make use of GROUP BY and HAVING (max(...)) clauses.

Data never sleeps

View solution in original post

1 REPLY 1
LinusH
Tourmaline | Level 20

Create the closiness column, and make use of GROUP BY and HAVING (max(...)) clauses.

Data never sleeps

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1226 views
  • 0 likes
  • 2 in conversation