BookmarkSubscribeRSS Feed
StudentPhil
Calcite | Level 5
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?
9 REPLIES 9
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
StudentPhil
Calcite | Level 5
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
StudentPhil
Calcite | Level 5
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.
Robert_Bardos
Fluorite | Level 6
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
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
StudentPhil
Calcite | Level 5
Thanks for your time Scott
StudentPhil
Calcite | Level 5
Many thanks Robert - that solved it. I really appreciate it!
deleted_user
Not applicable
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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 9 replies
  • 2306 views
  • 0 likes
  • 4 in conversation