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

I have no idea how to solve this problem. Could anyone help me to debug? thanks.

code:

%macro rmhistory( t);
   proc import datafile="D:\Users\emma\Documents\DDS\RMTable\file.txt" out=file replace;
   run;

   DATA rm_all;
   RUN;

    %do i=1 %to &t;
         data _null_;
            set file;
            if _n_=&i then do;
               call symput('ss', aa);
            end;
         run;
         %put &ss &i;
         proc import datafile="D:\Users\emma\Documents\DDS\RMTable\&ss" out=rm&i replace;
         SHEET="RMTable";
         run;
  
   data rmyyyymm&i;
            set rm&i;
            FORMAT yyyymm $6.;
            yyyymm = substr(&ss,1,6);
   run;

         data rm_all;
         set rm_all rmyyyymm&i;
         run;
     %end;
%mend rmhistory;
%rmhistory(1);

 

error message:

MPRINT(RMHISTORY):   data rmyyyymm1;
MPRINT(RMHISTORY):   set rm1;
MPRINT(RMHISTORY):   FORMAT yyyymm $6.;
NOTE: Line generated by the macro variable "SS".
1     201801_RMTableV1.xlsx
            ---------------
            22
            557
ERROR: DATA STEP Component Object failure.  Aborted during the COMPILATION phase.
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, ><,
              >=, AND, EQ, GE, GT, LE, LT, MAX, MIN, NE, NG, NL, OR, ^=, |, ||, ~=.

ERROR 557-185: Variable _RMTableV1 is not an object.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds

MPRINT(RMHISTORY):   yyyymm = substr(201801_RMTableV1.xlsx,1 ,6);
MPRINT(RMHISTORY):   run;

MPRINT(RMHISTORY):   data rm_all;
MPRINT(RMHISTORY):   set rm_all rmyyyymm1;
MPRINT(RMHISTORY):   run;

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Welcome to the SAS communities 🙂

 

I believe the problem is the fact that a SAS data set can not begin with a number 

 

EDIT: On second thought, I don't think so. I think you need to replace this

 

   data rmyyyymm&i;
            set rm&i;
            FORMAT yyyymm $6.;
            yyyymm = substr(&ss,1,6);
   run;

with this

   data rmyyyymm&i;
            set rm&i;
            FORMAT yyyymm $6.;
            yyyymm = substr("&ss",1,6);
   run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Welcome to the SAS communities 🙂

 

I believe the problem is the fact that a SAS data set can not begin with a number 

 

EDIT: On second thought, I don't think so. I think you need to replace this

 

   data rmyyyymm&i;
            set rm&i;
            FORMAT yyyymm $6.;
            yyyymm = substr(&ss,1,6);
   run;

with this

   data rmyyyymm&i;
            set rm&i;
            FORMAT yyyymm $6.;
            yyyymm = substr("&ss",1,6);
   run;
EmmaKao
Calcite | Level 5
Thank you, it works.
Kurt_Bremser
Super User

Since you have a Base SAS and not a macro problem, test your code first without macro logic:

proc import
  datafile="D:\Users\emma\Documents\DDS\RMTable\file.txt"
  out=file
  replace
;
run;

%let i=1;

data _null_;
set file;
if _n_=&i then do;
  call symput('ss', aa);
end;
run;

%put &ss &i;

proc import
  datafile="D:\Users\emma\Documents\DDS\RMTable\&ss"
  out=rm&i
  replace
;
sheet = "RMTable";
run;
  
data rmyyyymm&i;
set rm&i;
format yyyymm $6.;
yyyymm = substr(&ss,1,6);
run;

data rm_all;
set rm_all rmyyyymm&i;
run;

See that I added some consistent visual structure to your code to make it easier to read and understand (Maxim 12).

 

Without the macro around it, the ERROR message will now appear at the crucial point in your code, and alert you correctly to your mistake, which @PeterClemmensen already pointed out.

 

Macro development always starts with working SAS code; had you started with that, you would have realized you have to put a string (with quotes) in that position, and would have replace the text within that string with the macro variable (and not just inserted the macro variable without quotes)

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 585 views
  • 0 likes
  • 3 in conversation