below is the simple dataset.
input:
Output expected:
I am facing syntax error (screen shot at last) while executing below code .
could someone please help ?
data x;
length val $50;
val = "m1 = strip(put(count,best.)) ;"; count =1; output;
val = "m7 = strip(put(count,10.2))|| '/';"; count =2; output;
run;
proc sql noprint;
select distinct val into: stat separated by " " from x
;
%let stat = %nrbquote(&stat.);
quit;
%put R E S = &stat.;
data x2;
set x;
&stat.;
run;
Can you show the SAS code you are trying to use the macro processor to create?
Is it something like:
data x2;
set x;
m1 = strip(put(count,best.)) ;
m7 = strip(put(count,10.2))|| '/';
run;
If so then it is just your attempts to mess with the macro variable that is causing the errors.
To see what the PROC SQL code has created use %superq() macro function.
621 %put %superq(stat);
m1 = strip(put(count,best.)) ; m7 = strip(put(count,10.2))|| '/';
How many observations will X have? Will the generated macro variable get to be longer than 64K bytes?
It might be easier to just write the code to a file instead.
filename code temp;
data _null_;
set x;
file code;
put val;
run;
data x2;
set x;
%include code / source2;
run;
Plus the SAS log will be easier to read.
Can you show the SAS code you are trying to use the macro processor to create?
Is it something like:
data x2;
set x;
m1 = strip(put(count,best.)) ;
m7 = strip(put(count,10.2))|| '/';
run;
If so then it is just your attempts to mess with the macro variable that is causing the errors.
To see what the PROC SQL code has created use %superq() macro function.
621 %put %superq(stat);
m1 = strip(put(count,best.)) ; m7 = strip(put(count,10.2))|| '/';
How many observations will X have? Will the generated macro variable get to be longer than 64K bytes?
It might be easier to just write the code to a file instead.
filename code temp;
data _null_;
set x;
file code;
put val;
run;
data x2;
set x;
%include code / source2;
run;
Plus the SAS log will be easier to read.
Not sure what's going on with the statement causing the error but try removing the "space". It might be a tab or some other unprintable character. Try this:
val = "m7 = strip(put(count,10.2))!!'/';";
I also suspect there are better ways to do what you want, but since you haven't explained what that is, I'll leave it at that.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.