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

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;

sql macro.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Try this:

proc sql;

select count (distinct year_mth) into:num trimmed

from have

;

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Try this:

proc sql;

select count (distinct year_mth) into:num trimmed

from have

;

--
Paige Miller
Reeza
Super User

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 ...

jiangmi
Calcite | Level 5

I didn't realized that modification in sql.

Thanks.

Joe

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1426 views
  • 3 likes
  • 3 in conversation