I want to add a column to an existing data table in a macro step. I've already connected to a database and extracted the files of interest. The filename contains the specific lot ID but it is no where in the data table itself. So, I want to create a new column that contains the lot designation. In the snippet below, the sql portion works fine but the subsequent data step doesn't. More specifically, the part that fails is passing the macro variable in the data steps. Any help would be greatly appreciated.
options symbolgen mprint;
%macro loop;
%do i=1 %to 10;
proc sql;
create table &&ParamList&i.._data as
select *
from Prod.&&ParamList&i.._DATA;
quit;
data &&ParamList&i.._data;
set &&ParamList&i.._data;
Lot_ID=%str(%'&&ParamList&i%'); /* Here's where the issue is */
%end;
%mend;
%loop;
The following works but it's comp[lately manual...
data xyz_data;
set xyz_data;
runs='xyz';
run;
Here's an example of reading the current data set name and parsing a value from that. You should set length for the SETNAME variable for what you expect.
data example; set sashelp.class indsname=dsn; setname = scan(dsn,2,'.'); run;
and from multiple datasets when combining them. Not a particularly useful set but shows an example:
data example; set sashelp.class sashelp.cars indsname=dsn; setname = scan(dsn,2,'.'); run;
I
Here's an example of reading the current data set name and parsing a value from that. You should set length for the SETNAME variable for what you expect.
data example; set sashelp.class indsname=dsn; setname = scan(dsn,2,'.'); run;
and from multiple datasets when combining them. Not a particularly useful set but shows an example:
data example; set sashelp.class sashelp.cars indsname=dsn; setname = scan(dsn,2,'.'); run;
I
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.