my merge statment generates missing value for the first dataset
plesae see the attached two datasets. the real datasets are very long with many columns.
These two datasets were generated by sas macro.
Now I want to merge these two together.
data first;
set first1 first2;
by _NAME_;
run;
proc print data = first;
run;
the problem is,
the data generated actually put the first one into the first one, and the second one, the values are all missing
sample datasets attached
I just ran the following code, I'll paste my output below. Not sure what you are looking for but if that's the output you are getting I'd check the inputs:
data one;
infile cards dsd;
informat name $3. _1af _1af2 8.;
input name _1af _1af2;
cards;
c1a,1083,187
;run;
data two;
infile cards dsd;
informat name $3. _2af _2f2 8.;
input name$ _2af _2f2;
cards;
c1a,1083,187
;run;
data want;
set one two;
by name;
run;
name | _1af | _1af2 | _2af | _2f2 |
c1a | 1083 | 187 | ||
c1a | 1083 | 187 |
Thanks. Now I understand why you are confused. No wonder why SAS is confused too.
i want to have a table
name _af1 _af2
c1a 1086 187
c2a 1083 1
i need them to be vertically added, not horizontally appended
i hope it is clear enough
name | _1af | _1af2 | _2af | _2f2 |
c1a | 1083 | 187 | ||
c1a | 1083 | 1 |
You need to change the variables in the second dataset:
data want;
set one
two(rename=(_2af=_1af _2f2=_1af2));
by name;
run;
Thank you very much. This works.
The problem is my original two tables are generated by sas macro. It is time consuming to change name one by one.
Would you please provide sas macro code?
If you are generating the names in a macro then that would be the place to execute this code while the macro knows what they are.
I agree, manipulate this within the original macro to get the desired variable names.
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.