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
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.