DATA Step, Macro, Functions and more

What is wrong with this?

Reply
Occasional Contributor
Posts: 14

What is wrong with this?

do i=1 to i<=14;
x=i;
call symput('j',x);
if
/*blablablabla*/
then Exp&j=Price;

i=i+1;
end;

I get the error message:
(for the Exp&j=Price statement I have used.)
ERROR 180-322: Statement is not valid or it is used out of proper order.
Valued Guide
Posts: 2,175

Re: What is wrong with this?

> do i=1 to i<=14;
> x=i;
> call symput('j',x);
> if
> /*blablablabla*/
> then Exp&j=Price;
>
> i=i+1;
> end;
>
> I get the error message:
> (for the Exp&j=Price statement I have used.)
> ERROR 180-322: Statement is not valid or it is used
> out of proper order.

apart from anything else, you don't know how to use macro variables in a data step
> call symput('j',x);
> if
> /*blablablabla*/
> then Exp&j=Price;

&j gets the compile-time value, not the run time value
Until you appreciate this, avoid call symput()
Valued Guide
Posts: 632

Re: What is wrong with this?

You will also want to look at the form of the iterative DO statement. I doubt that this one will do what you intend.

do i=1 to i le 14;

Art
Valued Guide
Posts: 2,175

Re: What is wrong with this?

ArtC's point is fundamental to learning SAS programming. Data processing like iterative DO loops is central to the purpose and capabilities of DATA steps.
It is possible you want subscripting to select fom a list. That functionality is a typical activity used in an iteration. SAS provides that in DATA steps with ARRAY handling. Not with ampersand.
To learn the basics of SAS programming read and try the examples in Documentation.

welcome to SAS

peterC
Ask a Question
Discussion stats
  • 3 replies
  • 147 views
  • 0 likes
  • 3 in conversation