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

I try to use a macro variable "num" like this,

proc sql;

     select max(num) into :num
     from dsn2;

quit;

data asd2;

     set asd;

     array a _COL3-_COL#

     arrat b COL3-COL#

     do i= 1 to dim(&num);

     b(i)=input(a(i),best12.);

run;

well, it doesn't work, but if I do this, It seems works

proc sql;

     select max(num) into :num
     from dsn2;

quit;

*******;

%let numb=#

data asd2;

     set asd;

     array a _COL3-_COL&numb;

     arrat b COL3-COL&numb;

     do i= 1 to dim(&numb);

     b(i)=input(a(i),best12.);

run;

I don't why.

Anyone can pls tell me? THX!

1 ACCEPTED SOLUTION

Accepted Solutions
polingjw
Quartz | Level 8

%LET eliminates any leading and trailing blanks.

View solution in original post

9 REPLIES 9
polingjw
Quartz | Level 8

%LET eliminates any leading and trailing blanks.

rpg163
Calcite | Level 5

so you mean when using

proc sql;

     select max(num) into :num
     from dsn2;

quit;

"num" actually contains blanks?

polingjw
Quartz | Level 8

Try this and you will see:

%put col#

%let num=#

%put col#

rpg163
Calcite | Level 5

You are right!!

THX!!!

Tom
Super User Tom
Super User

You also have a syntax error in your interative DO statement.  Either pass the name of the array to the DIM() function or just use the macro variable as the upper bound on the array.

do i= 1 to dim(A);

do i= 1 to #

polingjw
Quartz | Level 8

There were a couple of other errors in the original post (DO without END and ARRAY misspelled "arrat").  I suspect that rpg163 might have the same problem that I do with these forums - not being able to paste code into the editor.

Ksharp
Super User

You can use Ctrl + c    and   Ctrl + v    to bring your code into the forum.

Another workaround is using macro function to trim these blanks.

%let num=%trim(%left(&num));

Ksharp

rpg163
Calcite | Level 5

THX! I will try this.

rpg163
Calcite | Level 5

You are right.

I missed sth. here.

sas-innovate-2024.png

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.

 

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
  • 9 replies
  • 1078 views
  • 0 likes
  • 4 in conversation