This code doesn't work why?
Since your datasets contain identically named columns (and I suppose the contain the same logical values), you do not want to merge or join, you want to stack the dataset by using both in the same SET statement; if they are already ordered by acc_number, you can preserve that order with a BY statement:
data newcollection;
set
balance_bank1sorted
balance_bank2sorted
;
by acc_number;
run;
This is called interleaving.
Regarding your question #1:
NO. A SQL join and a data step merge work differently, and produce completely different results when you have a many-to-many relationship; also, the data step MERGE tolerates identically named columns (and usually results in unexpected behavior), while SQL (rightfully) gives you a WARNING for that.
Please post your SAS log including any notes. Without this evidence we don't know what your problem is.
This is the code:
PROC IMPORT OUT=Balance_Bank1
DataFile = "/home/nguityn0/Balance_Bank.xlsx"
dbms=xlsx REPLACE;
Sheet="Sheet1";
getnames=NO;
RUN;
DAtA Balance_Bank3;
Format Acc_Number Date Debit Credit;
SET balance_bank1;
RUN;
This is the log:
</
You need to examine the data in your dataset WORK.BALANCE_BANK1. It contains 4 variables and 5 observations. Has it been populated as you expect? The notes in the following DATA step suggest you aren't getting the expected variable names and that may have something to do with the GETNAMES = NO statement. What happens if you try GETNAMES = YES?
I changed the GETName = Yes. It doesn't give me the order that I want.
Yes, I have four varialbes: Acc_Number Date Debit Credit and 5 observations.
Regards,
Blue Skey
Well your program doesn't include PROC SORT if you are referring to row order.
Your response helped me a lot.
Thanks for it.
Respectfully,
Guity
The program is different from the first post. I thought the merging process didn't work properly?
Also, what are the variable names in Balance_Bank1 after import?
I'm guessing that the variables such as Acc_Number are probably not assigned correctly and thus cannot be merged.
proc contents data=Balance_Bank1 varnum;
run;
Run this and show us the list of variables.
I have not learned the code you put here. I am a new learner and I need to stick to the codes that the instructor is teaching us.
Regards,
Blue Sky
copy and paste, then submit.
It will work.
I ran your codes and this is what I got:
Variable Type Len Format Label
1 Date Num 8 MMDDYY10. Date
2 Debit Num 8 BEST. Debit
3 Credit Num 8 BEST. Credit
4 Acc_Number Num 8 BEST. Acc_Number
Respectfully,
Blue Sky
I assume your title should say "Change the order of OBSERVATIONS", not "change the order of variables", as the order of variables would not affect a merge.
In any event, I think your two PROC IMPORTs wind up causing errors and don't create data sets. But as stated by @SASKiwi , show us the LOG of this entire section of code, all of the LOG, that's 100%, every single character in the LOG for this part of the code, with nothing chopped out, and without you selecting parts to show us and not showing us other parts.
Hello PaigeMiller,
Variables are columns or fields and observations are rows.
I need to change the order of variables.
Respectfully,
Blue Sky
@GN0001 wrote:
Hello PaigeMiller,
Variables are columns or fields and observations are rows.
I need to change the order of variables.
Respectfully,
Blue Sky
So you say you get errors, but you haven't shown us the errors in the LOG you provided.
You don't need to change the order of variables to achieve a merge. None of what you said or showed us makes sense.
Hello,
Are you saying observation orders are not important? Can I merge two data sets although the order of variables are different?
Respectfully,
Blue sky
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.