DATA Step, Macro, Functions and more

Passing a string from one data step to another...

Reply
Occasional Contributor
Posts: 7

Passing a string from one data step to another...

Hello,

Wondering if anyone can please point me in the right direction here. I'm trying to pass a character value from one dataset to another, so I'm trying to use CALL SYMPUT. Let's say my variable name is ID and my values are in the format 999.XXX.999

My data step is as follows:

DATA _NULL_;
SET COUPLESET2;
CALL SYMPUT ('PASS_ID',ID);
RUN;

But then when I try to assign this to a variable in another dataset as follows:

DATA TEMP;
SET NEWDATA;
NEWID = &PASS_ID;
RUN;

SAS very politely tells me that it's expecting a numeric operator. I thought maybe the periods were messing things up, but when I remove them, I still get an error. So then I thought maybe it's because I'm starting with a number, but when I start with a character, it creates a new variable the name of which is the value.

The process works great if the value is numeric, but I can't seem to get it to work with my string. Any thoughts please?
Super Contributor
Super Contributor
Posts: 3,174

Re: Passing a string from one data step to another...

It's a fact that you are only going to pass the "last observation's value". Explain why you feel compelled to use SAS macro variable to do work that typically occurs with other SAS facilities, especially without considering how/when macro variables are resolved (during compilation)?

Suggest you back-up and explain what you are attempting to accomplish with this task and divorce the verbiage from the SAS programming language altogether.

Scott Barry
Occasional Contributor
Posts: 7

Re: Passing a string from one data step to another...

Thanks for posting back Scott. Yes, I know that this only returns the "last observation value"; I actually have this in a loop, so it actually passes multiple values from each record of a dataset, one record at a time, to a series of other steps.

I'm trying to grab a string from one record in a dataset, and assign it to a pseudo-randomly selected record in another dataset, based on a series of rules and probability distributions. It's part of a bigger simulation algorithm I'm trying to get to work.

I don't feel compelled to use a SAS macro variable if there are other options, though I don't know what those would be (to iteratively pass the value from one dataset to another - without getting into more complex syntax like sysfunc and getvarc) - so if there's something else, let me know.

I'm well aware of how/when macro variables are resolved, and they resolve fine in my syntax.

Thanks.
Super Contributor
Super Contributor
Posts: 3,174

Re: Passing a string from one data step to another...

Then, I suggest in the future that you not post bogus code that doesn't apply to what it is that you are trying to accomplish - what that does is waste others' time in the process. If you are using some type of DO / END loop to do whatever (with assigning multiple, unique macro variables, and then I suppose you are using SYMGET to retrieve them and are doing some type of INPUT function to convert back to a numeric, then post that code for meaningful application and feedback from forum subscribers.

My suggestion is that you consider reading your file WORK.COUPLESET2 into a second DATA step, capturing some quantity of SAS variable values using DO UNTIL (EOF1) / SET.... END=EOF1 / END, followed by another DO UNTIL(EOF2) / SET .... END=EOF2 / END and make use of your SAS variables with assignment statements.

Without seeing value length ranges for your COUPLESET2 file which you mentioned about passing using macro variables, if you intend to go the macro var route, you will want to look at declaring with a LENGTH or ATTRIB statement the variable(s) that you are passing.

Scott Barry
SBBWorks, Inc.
Occasional Contributor
Posts: 7

Re: Passing a string from one data step to another...

Thanks again Scott....though I'm clearly not explaining myself very well. Thank you for your suggestion, but it doesn't actually solve my issue. Thanks for trying though....I'll keep plugging away at it.
Frequent Contributor
Posts: 106

Re: Passing a string from one data step to another...

Isn't this solved very simply by just specifying
[pre]
DATA TEMP;
SET NEWDATA;
NEWID = "&PASS_ID";
RUN;
[/pre]
Note the quotes around the macro variable.

Robert
Super Contributor
Super Contributor
Posts: 3,174

Re: Passing a string from one data step to another...

My point is that you need to share exactly what code is not working for you, since it is not that code you supplied in your original post. And provide it in the form of a pasted SAS-generated log with all code revealed and any additional diagnostic output needed (PUTLOG command(s), PROC CONTENTS, other displays) to accurately explain your problem.

Scott Barry
SBBWorks, Inc. Message was edited by: sbb
Occasional Contributor
Posts: 7

Re: Passing a string from one data step to another...

Thanks for your time Scott
Occasional Contributor
Posts: 7

Re: Passing a string from one data step to another...

Many thanks Robert - that solved it. I really appreciate it!
N/A
Posts: 0

Re: Passing a string from one data step to another...

you can use this function symget
data _null_;
set crackman;
call symput("PASS_ID"||left(_N_),ID);
run;
data yourdatset;
set crackman;
var=symget("PASS_ID"||left(_N_));
run;maybe this message will help you
Ask a Question
Discussion stats
  • 9 replies
  • 213 views
  • 0 likes
  • 4 in conversation