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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 1 reply
  • 830 views
  • 0 likes
  • 2 in conversation