BookmarkSubscribeRSS Feed
Subbarao
Fluorite | Level 6

Wanted to understand, Merge will retain the values in PDV or intializes the values when it reaches DATA statement.

 

DATA TESTA;

INPUT A B;

DATALINES;

10 20

20 30

30 40

;

RUN;

 

DATA TESTB;

INPUT C D;

DATALINES;

10 20

20 30

30 40

40 50

;

RUN;

 

DATA TESTC;

PUT _ALL_;

MERGE TESTA TESTB;

PUT _ALL_;

RUN;

 

when i see the log 

 

a=. b=. c=. d=. _ERROR_=0 _N_=1

a=10 b=20 c=10 d=20 _ERROR_=0 _N_=1

a=10 b=20 c=10 d=20 _ERROR_=0 _N_=2

a=20 b=30 c=20 d=30 _ERROR_=0 _N_=2

a=20 b=30 c=20 d=30 _ERROR_=0 _N_=3

a=30 b=40 c=30 d=40 _ERROR_=0 _N_=3

a=30 b=40 c=30 d=40 _ERROR_=0 _N_=4

a=. b=. c=40 d=50 _ERROR_=0 _N_=4

a=. b=. c=40 d=50 _ERROR_=0 _N_=5

NOTE: There were 3 observations read from the data set WORK.TESTA.

NOTE: There were 4 observations read from the data set WORK.TESTB.

NOTE: The data set WORK.TESTC has 4 observations and 4 variables.

NOTE: DATA statement used (Total process time):

      real time           0.03 seconds

      cpu time            0.01 seconds

 

What is happening with MERGE statement?? Can somebody can help me in understanding this??

3 REPLIES 3
Tom
Super User Tom
Super User

On the fourth time through the data step there are no more records available from TESTA so the variables (A and B) from TESTA are set to missing.

What is your question?

 

Loko
Barite | Level 11

Hello,

 

Answering to your question the values in PDV are retained. Maybe it is easier to understand if you use a more appropriate form of merge statement.

 

DATA TESTA;
INPUT key $ A B;
DATALINES;
a 10 20
a 20 30
c 30 40
;
RUN;

 
DATA TESTB;
INPUT key $ C D;
DATALINES;
a 100 200
b 200 300
c 30 400
c 400 500
;
RUN;

 

DATA TESTC;
PUT "before" _ALL_;
MERGE TESTA TESTB;
by key ;
PUT "after" _ALL_;
RUN;

MikeZdeb
Rhodochrosite | Level 12

Hi.  It might help to read a classic paper by Bob Virgile (SAS guy "extraordinaire") ...

 

How MERGE Really Works

http://www.lexjansen.com/nesug/nesug99/ad/ad155.pdf

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Update

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
  • 2312 views
  • 0 likes
  • 4 in conversation