DATA Step, Macro, Functions and more

problems of define a macro variable

Accepted Solution Solved
Reply
Contributor
Posts: 60
Accepted Solution

problems of define a macro variable

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!


Accepted Solutions
Solution
‎12-29-2011 08:57 AM
Regular Contributor
Posts: 171

Re: problems of define a macro variable

%LET eliminates any leading and trailing blanks.

View solution in original post


All Replies
Solution
‎12-29-2011 08:57 AM
Regular Contributor
Posts: 171

Re: problems of define a macro variable

%LET eliminates any leading and trailing blanks.

Contributor
Posts: 60

Re: problems of define a macro variable

so you mean when using

proc sql;

     select max(num) into :num
     from dsn2;

quit;

"num" actually contains blanks?

Regular Contributor
Posts: 171

problems of define a macro variable

Try this and you will see:

%put col#

%let num=#

%put col#

Contributor
Posts: 60

problems of define a macro variable

You are right!!

THX!!!

Super User
Super User
Posts: 6,495

problems of define a macro variable

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 #

Regular Contributor
Posts: 171

problems of define a macro variable

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.

Super User
Posts: 9,662

problems of define a macro variable

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

Contributor
Posts: 60

problems of define a macro variable

THX! I will try this.

Contributor
Posts: 60

Re: problems of define a macro variable

You are right.

I missed sth. here.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 240 views
  • 0 likes
  • 4 in conversation