DATA Step, Macro, Functions and more

Passing a variable to another dataset

Reply
Regular Contributor
Posts: 173

Passing a variable to another dataset

Hello,

I have 3 sas datasets : A,B, & C.
I want to merge A and B to create D. While in D, i would like to check the value of a variable from C.

DATA D;
MERGE A (IN=IN_A)
B (IN=IN_B);
BY EID;

IF IN_A AND IN_B THEN DO;
IF START_SW = " " THEN
CNT = CNT + 1;
*do more*

The If statement is not reconizing the variable START_SW, which is defined in Data C. How do I pass Start_sw to dataset D?

Thanks for any input!!
Kevin
Super Contributor
Super Contributor
Posts: 3,174

Re: Passing a variable to another dataset

You would get most effective feedback by sending the diagnostic output from your SASLOG to include a PUTLOG _ALL_; command revealing all variable values. Any other feedback is a virtual crap-shoot, especially given that we don't know what your input WORK.A and WORK.B variable values contains with each DATA step pass.

Scott Barry
SBBWorks, Inc.
Regular Contributor
Posts: 173

Re: Passing a variable to another dataset

thnx for your reply sbb.
I used PUTLOG _all_ to see the values of all.

the value of the variable I need is blank.
Let me ask a basic/stupid question: Can you pass a variable from one dataset X to another dataset Y without reading X?

If the answer is NO, then that's the problem I m facing.
I am merging 2 datasets (A & B) to create C. While I m in C, I need to access the variable from X. X contains only on row of data. If I use set to read X it would screw up my merge. Because the 2 files I am merging (A & B) contain multiple rows. The merge would stop after reading just one row. I hope I am explaining my problem clearly.

help please! Smiley Happy
Super Contributor
Super Contributor
Posts: 3,174

Re: Passing a variable to another dataset

From your recent post, you gave some indication that there is only one row and variable/column you wish to pass to another DATA step. So, yes, you can use CALL SYMPUT in "data step #1" to generate a SAS macro variable.

And in "data step #2", you can use a RETAIN statement to access the macro variable, assigning a SAS data variable / column value, referencing the macro variable using double-quote marks in the RETAIN statement.

Scott Barry
SBBWorks, Inc.
Regular Contributor
Posts: 173

Re: Passing a variable to another dataset

sbb, your suggestion worked !!!
Thank you !!!!
Ask a Question
Discussion stats
  • 4 replies
  • 150 views
  • 0 likes
  • 2 in conversation