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

sas-innovate-2024.png

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.

 

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
  • 816 views
  • 3 likes
  • 3 in conversation