BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_inquisitive
Lapis Lazuli | Level 10

What is the purpose of resetting temporary variables many1 and many2 in following code. 

data pairs oddballs;
	many1=0;
	many2=0;
	merge many1 ( in = many1 )
		many2 ( in = many2 );
	by partkey;

	if many1 and many2 then
		output pairs;
	else output oddballs;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

This type of code is used for many-to-many matches.  For example, let's say:

 

  • MANY1 contains 3 observations per PARTKEY
  • MANY2 contains 5 observations per PARTKEY
  • The objective is to output 3 observations per PARTKEY, matching the first from MANY1 with the first from MANY2, the second from MANY1 with the second from MANY2, etc.  Discard any that are left over from the data set containing more observations.

That's what this program accomplishes ... matching based on whichever data set has fewer observations, and putting those matched observations into PAIRS.  Discarding any that are left over without a match, putting them into ODDBALLS.

View solution in original post

2 REPLIES 2
ballardw
Super User

No practical purpose served that I can tell. If you found this code somewhere the assignments might be an artifact left in from previous code tested.

Or someone misunderstanding how temporary variables work in SAS.

Astounding
PROC Star

This type of code is used for many-to-many matches.  For example, let's say:

 

  • MANY1 contains 3 observations per PARTKEY
  • MANY2 contains 5 observations per PARTKEY
  • The objective is to output 3 observations per PARTKEY, matching the first from MANY1 with the first from MANY2, the second from MANY1 with the second from MANY2, etc.  Discard any that are left over from the data set containing more observations.

That's what this program accomplishes ... matching based on whichever data set has fewer observations, and putting those matched observations into PAIRS.  Discarding any that are left over without a match, putting them into ODDBALLS.

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!

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