When I run below code. I found only the first record of a column is populated by 'A' and other records are keeping blank for a column. Does someone help me to understand the reason? Thanks
data a;
a=' ';
b=1;
do i=1 to 10;
output;
end;
run;
data b;
a='A';
b=1;
run;
proc sort data=a; by b;run;
proc sort data=b; by b; run;
data c;
merge a b;
by b;
run;
SAS copies the values from a dataset only once. So for the first observation it reads variables A and B from dataset WORK.A and then overwrites the values read with the values read from WORK.B. But on the other observation there are no more records to read from WORK.B so the values read from WORK.A are not overwritten.
If you want to only keep the value of A from WORK.B then drop the variable from WORK.A. You could do it in the step with the MERGE by using the DROP= dataset option.
data c;
merge a(drop=a) b;
by b;
run;
SAS copies the values from a dataset only once. So for the first observation it reads variables A and B from dataset WORK.A and then overwrites the values read with the values read from WORK.B. But on the other observation there are no more records to read from WORK.B so the values read from WORK.A are not overwritten.
If you want to only keep the value of A from WORK.B then drop the variable from WORK.A. You could do it in the step with the MERGE by using the DROP= dataset option.
data c;
merge a(drop=a) b;
by b;
run;
What did you expect the output to be? Perhaps we can help you better if we see how you might be thinking. We can focus on what part of your hypothesis is incorrect.
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.