05-14-2016 09:45 PM
I am getting some errors in log report. I am using SAS 9.4. Any suggestions on how I can fix them.
options ls=64 nodate pageno=1;
libname states C:/Users/Documents/states;
%DO k = 1 %TO &num_states;
infile 'C:/Users/Documents/states' dlm=',';
length state $ 20;
length city $ 20;
input state $;
dsname = tranwrd(trim(state), ' ', '_');
call symput("name", state);
call symput("dsname", dsname);
%do i = 1 %to 50;
input rank city $ popul;
keep i state;
%Mend create_datasets ;
ERROR 180-322: Statement is not valid or it is used out of
ERROR 22-322: Syntax error, expecting one of the following:
a name, a quoted string, /, ;, _DATA_, _LAST_,
proc print data = state_data;
ERROR: FILE WORK.STATE_ DATA.DATA does not exist
title " Cities ";
05-14-2016 11:08 PM
Use MPRINT to see th values of STATE
Other issues I see:
1.Your libname should be outside your data step.
2. Not sure what the first loop should be doing, doesn't seem required?
3. Second SET statement with no data step start?
The key to writing a good macro is to start off with working code and expand it from there.
It looks like you're trying to read multiple files or datasets from a library?
Clarify what your objective is and others can make suggestions. Sometimes you don't even need a macro.
05-15-2016 04:37 AM
There are so many errors here, that the real fix is to stop writing macros. You need more work with base SAS before you will be ready to write macros. I will pick out just a few here.
Syntax for a libname statement requires quotes around the folder.
Libname and Infile referring to the same path, when one should be a folder and one should be a file.
Reading in POPUL when you never use it.
Repeating an INPUT statement 50 times, instead of executing the same INPUT statement 50 times.
Trying to keep "i" when it is not a variable in your data set.
Defining a macro, never executing it, and expecting the results to be available.
Get a program working without macros first. You will have enough work to do before you start writing macros.
05-15-2016 12:52 PM