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

I have a problem with a macro inside a user made transformation (not user written code).

This is the affected code:

 

proc transpose data = &var.&i.tmp out=&var.&i. let suffix=&suffix._amt ;
	by cust_id Period ;
	var antall&i.tmp ;
	id prodgrp&i._nm ;
	idlabel ProdGrp&i._label ;
run ;

But in the log, it looks like this:

NOTE: Line generated by the macro variable "SUFFIX".
325        _S_amt
             ____
             22
               ____
               202
MPRINT(PRODUKTANT):   proc transpose data = SaldoMin_amt1tmp out=SaldoMin_amt1 let suffix=_S_amt by cust_id Period 
;
MPRINT(PRODUKTANT):   var antall1tmp ;
MPRINT(PRODUKTANT):   id prodgrp1_nm ;
MPRINT(PRODUKTANT):   idlabel ProdGrp1_label ;
MPRINT(PRODUKTANT):   run ;

ERROR 22-322: Syntax error, expecting one of the following: ;, DATA, DELIM, DELIMITER, INDB, LABEL, LET, NAME, OUT, PREFIX, 
              SUFFIX.  

ERROR 202-322: The option or parameter is not recognized and will be ignored.

In the log, the semicolon after the suffix-code, seems to be missing, so the executed code seems to be 

 proc transpose data = SaldoMin_amt1tmp out=SaldoMin_amt1 let suffix=_S_amt by cust_id Period 

Not the expected 

 proc transpose data = SaldoMin_amt1tmp out=SaldoMin_amt1 let suffix=_S_amt ;
by cust_id Period 

It seems like the macro variable &suffix. somhow overwrites the semicolon, no matter if I move it down a few lines.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

While I can't be certain, it appears that some of the macro variables may have been quoted when they were created, and the software doesn't figure out how to unquote them in time.  If that's the problem, this should fix it:

 

%unquote(&nm.Lag&suffix.)= lag(antall&i.tmp);
%unquote(&nm.DIF&suffix.) = DIF(antall&i.tmp);

 

View solution in original post

4 REPLIES 4
Astounding
PROC Star

If there is an already-assigned value for &SUFFIX, the word "let" doesn't belong in the program.  Just remove it.

 

Technically, the macro statement would be %LET  instead of LET.  Either way, just remove it.   You're not trying to assign a value to &SUFFIX at that point, you're just trying to use the already-assigned value.

 

 

Ullsokk
Pyrite | Level 9

Great, I just used a legacy code, thought that was just some funny syntax, but removing it makes sense. Removed the let, which didnt affect my code in SAS studio (runs anyway) but removed that previous error in DI-studio. 

 

But I still have issues with this part of the macro in DI-studio:

data change&i.;
set &var.&i.tmp;
by cust_id ProdGrp&i._Desc Period;
&nm.Lag&suffix.= lag(antall&i.tmp);
&nm.DIF&suffix. = DIF(antall&i.tmp);
if first.ProdGrp&i._Desc then do;
&nm.Lag&suffix. = .;
&nm.DIF&suffix. = .;
end;
&nm.change_pct = divide(&nm.DIF&suffix. , &nm.Lag&suffix.)*100;
run;

which looks like this in the SAS DI-studio log, but runs without issue in SAS Studio:

   
MPRINT(PRODUKTANT):   data change1;
MPRINT(PRODUKTANT):   set SaldoMin_amt1tmp;
MPRINT(PRODUKTANT):   by cust_id ProdGrp1_Desc Period;
NOTE: Line generated by the macro variable "SUFFIX".
325         SaldoMinLag_Smin
            ________
            180
MPRINT(PRODUKTANT):   SaldoMinLag_Smin= lag(antall1tmp);
NOTE: Line generated by the macro variable "SUFFIX".
325         SaldoMinDIF_Smin
            ________
            180
10                                                         The SAS System                         13:17 Thursday, September 13, 2018

MPRINT(PRODUKTANT):   SaldoMinDIF_Smin = DIF(antall1tmp);
MPRINT(PRODUKTANT):   if first.ProdGrp1_Desc then do;
NOTE: Line generated by the macro variable "SUFFIX".
325         SaldoMinLag_Smin
            ________
            180
MPRINT(PRODUKTANT):   SaldoMinLag_Smin = .;
NOTE: Line generated by the macro variable "SUFFIX".
325         SaldoMinDIF_Smin
            ________
            180
MPRINT(PRODUKTANT):   SaldoMinDIF_Smin = .;
MPRINT(PRODUKTANT):   end;
NOTE: Line generated by the macro variable "NM".
325         SaldoMinEndring_pct
            ________
            180
MPRINT(PRODUKTANT):   SaldoMinEndring_pct = divide(SaldoMinDIF_Smin , SaldoMinLag_Smin)*100;
MPRINT(PRODUKTANT):   run;

ERROR 180-322: Statement is not valid or it is used out of proper order.
Astounding
PROC Star

While I can't be certain, it appears that some of the macro variables may have been quoted when they were created, and the software doesn't figure out how to unquote them in time.  If that's the problem, this should fix it:

 

%unquote(&nm.Lag&suffix.)= lag(antall&i.tmp);
%unquote(&nm.DIF&suffix.) = DIF(antall&i.tmp);

 

Ullsokk
Pyrite | Level 9

fantastic, that finally solved all the issues. Thank you so much, this has been driving med insane for the last days, since it worked regular sas code, but not as part of a transformation. Really strange how similar code in anoter transformation works without %unquote()

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1075 views
  • 0 likes
  • 2 in conversation