BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
abhinayingole
Obsidian | Level 7

below is the simple dataset.

 

input:

abhinayingole_1-1640804002678.png

 

Output expected:

abhinayingole_0-1640807302762.png

 

 

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;

 

 

abhinayingole_2-1640804148509.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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.

 

SASKiwi
PROC Star

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 358 views
  • 3 likes
  • 3 in conversation