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

@Tom Of course you are right.

Something like this would work

data combine;
  length identifier $20;
  identifier = ' ' ;
  set get_test1_nodup
      get_test2_nodup ;
  if identifier ='' then identifier=Spot_2||Spot_4||Spot_3;
run;

but is is not shorter or clearer than @mkeintz 's proposal.

I was keen to emphasize that variables could be processed at the top of the data step, before the SET statement is encountered, but my example fell flat on its face...

mkeintz
PROC Star

"There's more than one way to skin a cat".  So here's another way.  It has no explicit output and no call missing.  But it does take advantage of a DROP= parameter and conditional SET statement.  And it eliminates the unintended carry forward of stay stale identifier values.

 

data combine;
  set   get_test1_nodup
        get_test2_nodup  (drop=identifier in=in2);
  identifier=Spot_2||Spot_4||Spot_3;
  if in2 then set get_test2_nodup;
run;

The crucial point here is that the conditional SET is explicitly synchronized with reading data from get_test2_nodup in the unconditional SET.  

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
jhealthpolicy
Fluorite | Level 6

Thank you everyone for the replies -- this was very educational.

 

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!

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
  • 17 replies
  • 1596 views
  • 3 likes
  • 4 in conversation