Hi all,
How to modify the code to run successfully?
I want to use &faa in one data set.
%scan(symget('faa'),&i,|) can't run successfully too.
%macro ff; data a; if _n_=1 then do; aa='f|dd|ff'; call symputx('faa',aa); end; set xx; %let i=1; %do %until (%scan(&faa,&i,|) = ); %scan(&f,&i,|)='1'; %let i=%eval(&i+1); %end; run; %mend; %ff;
Thanks.
You have a basic macro timing problem. CALL SYMPUTX works at data step execution time, but the macro code is resolved while the macro creates the code that will later be compiled into a data step, so it will try to fetch the macro variable long before it is created.
The deeper issue here is that you try to abuse the macro language for something it is not meant to do: manipulate data.
To keep values across observations, use a RETAINed variable, or set a macro variable before the data step. To present valid code, we first need to know the data you start with, and what you want to get out of it.
Please supply an example dataset in a data step with datalines, and the expected result from it.
Anything macro executes before the SAS data step and that's why you've got a timing issue here. The macro %do loop executes before the SAS data step creates macro variable &faa.
Please explain what you're actually trying to do. There is a good chance that you don't need macro code at all.
What do you want to achieve? It seems as if you want to to set the variable "f", "dd" and "ff to 1. All variables seem to be alphanumeric, right? If yes, you don't need macro-code, but an array:
data a;
set xx;
array vars[3] f dd ff;
do i = 1 to dim(vars);
vars[i] = '1';
end;
drop i;
run;
You have a basic macro timing problem. CALL SYMPUTX works at data step execution time, but the macro code is resolved while the macro creates the code that will later be compiled into a data step, so it will try to fetch the macro variable long before it is created.
The deeper issue here is that you try to abuse the macro language for something it is not meant to do: manipulate data.
To keep values across observations, use a RETAINed variable, or set a macro variable before the data step. To present valid code, we first need to know the data you start with, and what you want to get out of it.
Please supply an example dataset in a data step with datalines, and the expected result from it.
Thanks a lot.
I put the step of creating macro variable before this data set.
But I have a new question.
why I use double quotation marks in hash then the log generates issue?
When I replace them with single quotes('cmseq'), there's no problem.
Your double quotes are curly quotes and not typed from the keyboard. Use straight quotes. Type them yourself in the SAS editor.
data cm; if _N_=1 then do; dcl hash h(multidata:'Y'); h.definekey('usubjid', "cmseq"); h.definedata('qnam', 'qval'); h.definedone(); do until(eof); set sdtm.suppcm end=eof; cmseq=input(idvarval,best.); rc=h.add(); end; end;
It's not about double quotes.
Timing issue as you were told.
When the data step compiles, all variables must be known.
So:
%scan(&faa,&i,|)
must be resolved.
This is of course impossible in your scenario as &f is unknown at compile time.
Also note the inconsistency: you seem to have confused variables &f and &faa .
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.
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.