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?
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 ;
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.
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!
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.