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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 625 views
  • 0 likes
  • 2 in conversation