DATA Step, Macro, Functions and more

PDV in merge

Reply
Contributor
Posts: 39

PDV in merge

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??

Super User
Super User
Posts: 6,502

Re: PDV in merge

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?

 

Super Contributor
Posts: 305

Re: PDV in merge

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;

Valued Guide
Posts: 765

Re: PDV in merge

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

Ask a Question
Discussion stats
  • 3 replies
  • 250 views
  • 0 likes
  • 4 in conversation