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!

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!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 655 views
  • 0 likes
  • 2 in conversation