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?
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;
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;
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
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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: