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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

View solution in original post

3 REPLIES 3
ballardw
Super User

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

dwilliams1
Calcite | Level 5
ballardw,

THANK YOU! I really appreciate your help.

Dave
dwilliams1
Calcite | Level 5
Your response was quicker than me trying to edit my post to account for the sloppy cut/paste that I did!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 3 replies
  • 1254 views
  • 0 likes
  • 2 in conversation