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

Hi all,

 

I have an error and I don't know how to fix it. The problem occurs at the RENAME option in my macro. What is weird is that if I copy the MPRINT statement in the log (see below in Bold) and run it in SAS, I don't have an error and the dataset is created?

 

Here's the code: 

%** Input dataset  *;
  %if %nrbquote(&_DATA_.) ne %str( ) %then
  %do;
   %let z=1;
   %let _RENAME_=;
 
       %if %nrbquote(&_VARSQL_.) ne %str( ) %then
       %do;
          %do %until(%qscan(%nrbquote(&_VARSQL_.),&z,%str(,))=%str());
      %global var&z;
             %let var&z = %qscan(%nrbquote(&_VARSQL_.),&z,%str(,));
      %if %varexist(ds=&_DATA_., var=&&var&z) = 1 %then
      %do;
       %let _RENAME_ = &_RENAME_. &&var&z=_&&var&z;
      %end;
      %let z = %eval(&z+1);
     %end;
    %end;
   %if %nrbquote(&_RENAME_.) ne %str( ) %then %do; set &_DATA_.(rename=(%bquote(&_RENAME_.))); %end;
   %else %do; set &_DATA_.;  %end;
  %end;
  %else %do; %put "  ERROR : NO ENTRY DATA SET "; %end;
 
NOTE: Line generated by the macro function "BQUOTE".
1       STUDYID=_STUDYID AEREFID=_AEREFID AETERM=_AETERM AESEV=_AESEV AESER=_AESER AEACN=_AEACN AEREL=_AEREL
                         -------
                         79
1     ! AEOUT=_AEOUT AESCONG=_AESCONG AESDISAB=_AESDISAB AESDTH=_AESDTH AESHOSP=_AESHOSP AESLIFE=_AESLIFE
MPRINT(CREATESDTM):   set data.ae_1 (rename=(STUDYID=_STUDYID AEREFID=_AEREFID AETERM=_AETERM AESEV=_AESEV AESER=_AESER
AEACN=_AEACN AEREL=_AEREL AEOUT=_AEOUT AESCONG=_AESCONG AESDISAB=_AESDISAB AESDTH=_AESDTH AESHOSP=_AESHOSP
AESLIFE=_AESLIFE AESMIE=_AESMIE AECONTRT=_AECONTRT AESTDY=_AESTDY AEENDY=_AEENDY));
SYMBOLGEN:  Macro variable _SUB_ resolves to UPCASE(COMPRESS(AEANY)) = "YES"
MLOGIC(CREATESDTM):  %IF condition %nrbquote(&_SUB_.) ne   is TRUE
SYMBOLGEN:  Macro variable _SUB_ resolves to UPCASE(COMPRESS(AEANY)) = "YES"
MPRINT(CREATESDTM):   where UPCASE(COMPRESS(AEANY)) = "YES" ;
MPRINT(CREATESDTM):   run;
ERROR 79-322: Expecting a =.
 
Thanks for your help!
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You are out-complicating yourself. I take it you run a SQL select from dictionary.columns to get your variable names. You can do everything much easier by using call execute off sashelp.vcolumn in a data _null_ step:

data _null_;
set sashelp.vcolumn (where=(libname = "&lib." and memname = "&data." and /* insert your condition(s) here */)) end=eof;
if _n_ = 1 then call execute("proc datasets library=&lib.; modify &data.; rename");
call execute(cats(' ',name,'=',"&prefix.",name));
if eof then call execute(";quit;");
run;

PS I do not think the %bquote is necessary.

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

You are out-complicating yourself. I take it you run a SQL select from dictionary.columns to get your variable names. You can do everything much easier by using call execute off sashelp.vcolumn in a data _null_ step:

data _null_;
set sashelp.vcolumn (where=(libname = "&lib." and memname = "&data." and /* insert your condition(s) here */)) end=eof;
if _n_ = 1 then call execute("proc datasets library=&lib.; modify &data.; rename");
call execute(cats(' ',name,'=',"&prefix.",name));
if eof then call execute(";quit;");
run;

PS I do not think the %bquote is necessary.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1890 views
  • 0 likes
  • 2 in conversation