BookmarkSubscribeRSS Feed
fastb
Fluorite | Level 6

I have a dataset A that contains one observation and one variable (NMaxBlocks).  I created dataset C by joining datasetA with datasetB, and dataset B did not contain the variable NMaxBlocks.  Because B did not originally contain the variable NMaxBlocks, all observations in C that were originally in B now contain "." for the variable NMaxBlocks.  I want all observations in C that contain "." because they were originally part of B to contain the value for NMaxBlocks that originally appeared in A. (See attached exerpt of output from C- all "." in NMaxBlocks need to contain 4 from NMAxBlocks in the last observation in the dataset).  I know there is a simple way to do this, but I am not enough of an experienced SAS user to know how to do this yet.  Any ideas?


Capture.PNG
2 REPLIES 2
KoMartin66
Obsidian | Level 7

There are several ways to accomplish this, here's one using multiple SET statements within a DATA step.

DATA WORK.C ;

  IF _N_ = 1 THEN SET WORK.A ;

  SET WORK.B  ;

RUN ;

Astounding
PROC Star

Perhaps you would be better off learning how to combine A and B, rather than fixing the problem later.  If you are using a DATA step, it would be:

data C;

   if _n_=1 then set A;

   set B;

run;

If you are using SQL:

proc sql noprint;

   create table C as select * from A, B;

quit;

You would no longer have that single observation at the end, where the contents of A matches nothing from B.

Good luck.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1321 views
  • 1 like
  • 3 in conversation