BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
dcortell
Pyrite | Level 9

Hi all,  I'm testing the following:

%let var0="dog"n? "cat"n?;

%let var=%scan(&var0,1,?,m);
%put &var;

%let var2=%qtrim(%qscan(&var,1,%str(%")));
%put &var2;

%let j=1;


data test ;
length landing_page_url $300.;
input id landing_page_url $;
datalines;
10 cccc
5  dd
;
run;

proc freq data=test noprint;
tables landing_page_url / out=_&var2.&j (drop=count) missing;
run;

I'm getting a no real explicative error in the proc freq output:

83    proc freq data=test noprint;
84    tables landing_page_url / out=_&var2.&j (drop=count) missing;
SYMBOLGEN:  Macro variable VAR2 resolves to dog
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
SYMBOLGEN:  Macro variable J resolves to 1
NOTE: Line generated by the macro variable "J".
84    _dog1
       ---
       22
        ---
        76
ERROR 22-322: Syntax error, expecting one of the following: ;, (, AGREE, ALL, ALPHA, BDT, BIN, BINOMIAL, CELLCHI2, CHISQ, CL, CMH, 
              CMH1, CMH2, COMMONRISKDIFF, COMONMRDIFF, CONTENTS, CONVERGE, CROSSLIST, CUMCOL, DEVIATION, EXACT, EXPECTED, FISHER, 
              FORMAT, GAILSIMON, GS, JT, KAPPA, LINE, LIST, MAXITER, MAXLEVELS, MEASURES, MISSING, MISSPRINT, NOCOL, NOCUM, NOFREQ, 
              NOPERCENT, NOPRINT, NOROW, NOSPARSE, NOWARN, ODDSRATIO, OR, OUT, OUTCUM, OUTEXPECT, OUTPCT, PEARSONRES, PEARSONRESID, 
              PLCORR, PLOTS, PRINTKWTS, PRINTWTS, RELRISK, RISKDIFF, SCORE, SCORES, SCOROUT, SENSPEC, SPARSE, STDRES, STDRESID, 
              TABLE, TESTF, TESTP, TOTPCT, TREND, WARN.  
ERROR 76-322: Syntax error, statement will be ignored.

No idea why is not accepting the table name starting with underscore, as according to SAS documentation it should work

 

Any tips to share?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You can sometimes confuse the parser with syntax like that.  It generates code without any spaces, but the parser still treats it as multiple tokens instead of one.  Normally I see it more often when running the code inside a macro.

 

What I find the least confusing it to build the name into another macro variable and then use that to generate the code.

%let dsname=_&var2.&j;

proc freq data=test noprint;
  tables landing_page_url / out=&dsname (drop=count) missing;
run;

You can also just add some macro function around it.  In this case %UNQUOTE() is a good one.

proc freq data=test noprint;
  tables landing_page_url / out=%unquote(_&var2.&j)(drop=count) missing;
run;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

You can sometimes confuse the parser with syntax like that.  It generates code without any spaces, but the parser still treats it as multiple tokens instead of one.  Normally I see it more often when running the code inside a macro.

 

What I find the least confusing it to build the name into another macro variable and then use that to generate the code.

%let dsname=_&var2.&j;

proc freq data=test noprint;
  tables landing_page_url / out=&dsname (drop=count) missing;
run;

You can also just add some macro function around it.  In this case %UNQUOTE() is a good one.

proc freq data=test noprint;
  tables landing_page_url / out=%unquote(_&var2.&j)(drop=count) missing;
run;
dcortell
Pyrite | Level 9

The following did the job:

%let final=_&var2.&j;

proc freq data=test noprint;
tables landing_page_url / out=%unquote(&final) (drop=count) missing;
run;

Withotu the %unquote applied, the same error still was provided. Thanks Tom

Tom
Super User Tom
Super User

In that case it is probably the macro quoting you added to the macro variables with the use of %QSCAN() and %QTRIM().

 

You shouldn't need those for strings you are going to use to generate a name. None of the characters that are valid in a name need macro quoting.

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
  • 3 replies
  • 534 views
  • 0 likes
  • 2 in conversation