BookmarkSubscribeRSS Feed
Tamertmg
Fluorite | Level 6

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 =

Tamertmg_5-1657033134912.png

 

 

 

ZDF =

Tamertmg_6-1657033134922.png

 

 

Tamertmg_7-1657033134943.png

Figure 1 dataset A

 

 

Tamertmg_8-1657033134983.png

Figure 2. Dataset B

 

The outcome should be like this:-

Tamertmg_9-1657033135007.png

Figure 3. Desired outcomes

 

 

Thank you

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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.

Insert Log Icon in SAS Communities.png

 

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.

 

 

--
Paige Miller
Tamertmg
Fluorite | Level 6
Thank you Paige for the reply. I will share the SAS data as per instructions
Tom
Super User Tom
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 590 views
  • 0 likes
  • 3 in conversation