BookmarkSubscribeRSS Feed
KevinC_
Fluorite | Level 6
Hello,

I am merging SAS dataset A with SAS dataset C by the variable SP1. A comes from an input file. C comes from the result of a query. I want to write SP1 from A and SP2 from C to the merged SAS dataset D. However, SP2 from C is blank when it's written out. I checked the result of the query and SP2 is not blank. Can anyone tell me what i m doing wrong? Here is what i have:

DATA A;
INFILE IN1;
INPUT @01 SP1 $CHAR10.
@11 SPCD1 $CHAR03.;
proc sort, by sp1;


PROC DB2EXT OUT = C UNIQUE;
SELECT A.ENTITYID AS SP1,
B.ENTITYID AS SP2
FROM ADUADS01.ADVTB912 A,
ADUADS01.ADVTB912 B,
WHERE A.ENTITYID = B.ENTITYID
FOR READ ONLY;
RUN;
PROC SORT; BY SP1;

DATA D;
MERGE A (IN=IN_A)
C (IN=IN_C);
BY SP1;
IF IN_A AND IN_C THEN DO;
PUT @1 SP1
@11 SP2;
END;


Thank you so much for your help!!!
Kevin
2 REPLIES 2
KevinC_
Fluorite | Level 6
I guess the question could have been "how do i write a variable to a temporary SAS dataset?"

I could write it to an output file. But That's not really what I need. I m just running a series of merges. That's why I am using temporary sas datasets.

Thanks in advance for any input !!
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Need to see some SASLOG session output with PUTLOG _ALL_; commands in order to understand your data conditions -- you also may find this debugging technique revealing as well. Also, you should confirm that SP1 is consistent in both input files, specifically, if a "formatted value" is being displayed for diagnosis, you may find that the "SAS internal value" shows that the two sources are not equal. Lastly, using the PUTLOG _ALL_; command will show the IN= variable values from your MERGE operation -- info that could be very revealing for your own diagnosis.


Scott Barry
SBBWorks, Inc.

SAS Innovate 2025: Register Now

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!

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
  • 2 replies
  • 747 views
  • 0 likes
  • 2 in conversation