Hi, All,
In this case, &num was created by SQL to count the number of obs in data(have).
Instead using &num directly to create array, I have to assign the &num value to &end to make it work. Why?
The log screen was attached.
Thanks.
Joe
data have;
input year_mth @@;
cards;
201412 201411 201410
;run;
proc sql;
select count (distinct year_mth) into:num
from have
;quit;
%put check the new macro value: #
/*Why not working if use &num directly*/
data notwork;
array L (*) L01-L#
do i=01 to #
L(i)=i;
end;
run;
/*It works when converting by let statement*/
%let end = #
data yeswork;
array L (*) L01-L&end;
do i=01 to &end;
L(i)=i;
end;
run;
Try this:
proc sql;
select count (distinct year_mth) into:num trimmed
from have
;
Try this:
proc sql;
select count (distinct year_mth) into:num trimmed
from have
;
Because the macro variable has leading spaces so what the compiler sees is:
L. 3
Use the Trimmed option in your SQL to remove the spaces:
ie
...
Into :num Trimmed
from ...
I didn't realized that modification in sql.
Thanks.
Joe
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.