Could not use Macro Variable in a Data step!!!

Accepted Solution Solved
Reply
Contributor
Posts: 66
Accepted Solution

Could not use Macro Variable in a Data step!!!


Hello experts,

I have run into following issue;

%Let  Var= 20 30 40 50;

Data new;

input  NewVar @@;

Datalines;

&Var;

;

I am expecting a data set New as

NewVar

20

30

40

50

But SAS does keep throwing out errors!

Can you help me figure out where I voilated macro norms?

Thanks,

Raghu.


Accepted Solutions
Solution
‎09-12-2013 03:54 PM
Super User
Super User
Posts: 6,500

Re: Could not use Macro Variable in a Data step!!!

SAS doesn't expand macro statement inside of in-line data.

You could use the RESOLVE function.

%Let  Var= 20 30 40 50;

data new;

  input @;

  _infile_=resolve(_infile_);

  input  NewVar @@;

datalines;

&Var

;


But it will not work with more than one line of data when also using @@ on the INPUT statement.

You could convert to something like this.

%Let  Var= 20 30 40 50;

data new;

   infile cards truncover ;

  input @;

  _infile_=resolve(_infile_);

  do until (newvar=.);

    input  NewVar @;

     if newvar ne . then output;

   end;

datalines;

1 2 3

&Var

;

View solution in original post


All Replies
Solution
‎09-12-2013 03:54 PM
Super User
Super User
Posts: 6,500

Re: Could not use Macro Variable in a Data step!!!

SAS doesn't expand macro statement inside of in-line data.

You could use the RESOLVE function.

%Let  Var= 20 30 40 50;

data new;

  input @;

  _infile_=resolve(_infile_);

  input  NewVar @@;

datalines;

&Var

;


But it will not work with more than one line of data when also using @@ on the INPUT statement.

You could convert to something like this.

%Let  Var= 20 30 40 50;

data new;

   infile cards truncover ;

  input @;

  _infile_=resolve(_infile_);

  do until (newvar=.);

    input  NewVar @;

     if newvar ne . then output;

   end;

datalines;

1 2 3

&Var

;

Contributor
Posts: 66

Re: Could not use Macro Variable in a Data step!!!

Thank you Tom, I would not have done this on my own!

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 176 views
  • 0 likes
  • 2 in conversation