Hi,
I am trying to merge two datasets: dataset A and dataset B, and at the same time, I want to do some calculations based on the TOTAL and the LOS_TOTAL. I tried to merge the data set by year as it is the only variable that matches both datasets, but it did not work. I used the following data step:-
Data test;
Set test1;
Merge work.A
Work.B;
By year;
Run;
The merge should be based on the value (0,1) for variables (_3WX _2SF _4SQ _6SR _7SF _7WO 7ICU _5AA), if the value is 1 then take the same values of GRE and ZDF from the dataset B. If it is 0, then ignore it. If one observation contains value 1 in two different variables, then do a calculation. For example (ID 3 has value 1 for _2SF and _7ICU).
Now, I am stuck. I don’t know how to merge them. Also, I want to do the following calculation (e.g., ID 3):-
If total > 1 then GRE =
ZDF =
Figure 1 dataset A
Figure 2. Dataset B
The outcome should be like this:-
Figure 3. Desired outcomes
Thank you
I tried to merge the data set by year as it is the only variable that matches both datasets, but it did not work.
Saying "it did not work" and stopping there gives us no information about why it didn't work.
If there are errors in the log, then show us the entire log for this merge step, every single line, with nothing chopped out. Copy the log as text and paste it into the window that appears when you click on the </> icon.
If the output was not correct, then show us the output you got and the desired output.
Lastly, we cannot write programs to read data from screen captures. Data MUST be provided as SAS data step code, which you can type in yourself of follow these instructions.
Which observations for the year "2018/19" do you want to combine? Both of the pictures you posted have multiple observations with that value.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.