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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 982 views
  • 1 like
  • 3 in conversation