I have a data set named param.tbl which contains data that looks like this:
ID TIME CMT AGE ETA1
1.0000E+00 0.0000E+00 1.0000E+00 1.2000E+01 7.4460E-01
1.0000E+00 0.0000E+00 2.0000E+00 1.2000E+01 7.4460E-01
1.0000E+00 0.0000E+00 3.0000E+00 1.2000E+01 7.4460E-01
The actual data set has about 500 rows and I have presented a 3 row sample.
When I use the code below, I get the log below, and the data is not read in. Can someone tell me how to correct the code so that the data will be read into SAS?
LOG
I have attached code written to read the data set.
%do i=1% to 5;
data NEW_SUBJ&i;
infile "/folders/myfolders/test&i..nm7/PARAM.TBL" FIRSTOBS=2;
input ID TIME CMT AGE ;
RUN;
DATA NEW_SUBK&i;
SET NEW_SUBJ&i;
IF ID=. THEN DELETE;
RUN;
%END;
You seem to be using an interface like Enterprise Guide or SAS/Studio that submits your code to a remote SAS server. The error message is probably related to unbalanced quotes. Try restarting the SAS session you are using to run the code and see if that helps.
Your posted code has two obvious problems. First is the misplaced % on the %TO part of your %DO loop.
Second is that to use a %DO loop you need to wrap that code into a macro definition. Which means you also need to call the macro once it is defined.
So try something like this:
%macro read5;
%do i=1 %to 5;
data NEW_SUBJ&i;
infile "/folders/myfolders/test&i..nm7/PARAM.TBL" firstobs=2 truncover;
input ID TIME CMT AGE ;
if id=. then delete;
run;
%end;
%mend read5;
options mprint;
%read5;
Turning on the MPRINT option will have SAS show the lines of code that the macro generates in the LOG.
They key is this
NOTE: The quoted string currently being processed has become more than 262 bytes long. You might have unbalanced quotation marks.
at the beginning of the log. You had unbalanced quotes in previous code. Restart your SAS session and run the code again.
After several minutes of staring at your code wondering what could be wrong it struck me:
%do i=1% to 5;
is probably a typo for for this intended code:
%do i=1 to 5;
The percent sign after the 1 probably yields the message you get, although I didn't test that.
Hope this helps,
-- Jan.
You seem to be using an interface like Enterprise Guide or SAS/Studio that submits your code to a remote SAS server. The error message is probably related to unbalanced quotes. Try restarting the SAS session you are using to run the code and see if that helps.
Your posted code has two obvious problems. First is the misplaced % on the %TO part of your %DO loop.
Second is that to use a %DO loop you need to wrap that code into a macro definition. Which means you also need to call the macro once it is defined.
So try something like this:
%macro read5;
%do i=1 %to 5;
data NEW_SUBJ&i;
infile "/folders/myfolders/test&i..nm7/PARAM.TBL" firstobs=2 truncover;
input ID TIME CMT AGE ;
if id=. then delete;
run;
%end;
%mend read5;
options mprint;
%read5;
Turning on the MPRINT option will have SAS show the lines of code that the macro generates in the LOG.
Once I used the macro and edited the do loop it ran with no problem.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.