BookmarkSubscribeRSS Feed
OS2Rules
Obsidian | Level 7
Hi All:

This is more programming than procedure oriented ...

I build a list of table names using a PROC SQL using the INTO.

I then use this macro variable to read a set of tables into one:

DATA ACTIVITY:
SET &members;

etc.

It could process up to 127 "members" into the single table.

My question is: can I add a variable to ACTIVITY that identifies which table in the list of &members each observation came from?

Thanks in advance.
6 REPLIES 6
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Add a RETAIN statement that resolves a SAS variable in your DATA step. In the statement, declare the macro variable in double-quotes as the variable value. Add an ATTRIB statement to document the variable.

Scott Barry
SBBWorks, Inc.
OS2Rules
Obsidian | Level 7
Scott:

That won't work - the &members macro variable contains up to 127 table names that are basically being concatenated.

I need to know which one contributed each observation.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Okay, then use the IN= parameter on the SET statement, and assign a concatenated string of subfield values (how about one char per input file), and use the "1" or "0" indicator from the IN= to detect when one of your input files (to the SET) is contributing an observation.

Scott Barry
SBBWorks, Inc.
Flip
Fluorite | Level 6
What if you create your macro variable with (in = ) options built in. You may still need create a string to keep those values as in = vars are dropped at the end of the data step.

select name || '(in = ' || name ||')' separated by ' ' into :
data_null__
Jade | Level 19
There is a SET statement option for this in V9.2 if you have less than 9.1.3 like me you can do something like....

[pre]
data one two three four five;
x = 1;
run;

proc sql;
select cats(memname,'(in=__',memname,')') into :codeGen separated by ' '
from dictionary.members where libname eq 'WORK';
quit;
run;
%put NOTE: CODEGEN=&codegen;
data all;
set &codegen;
array _
  • __:;
    length origin $32;
    origin = substr(vname(_[whichn(1,of _
  • )]),3);
    run;
    proc print;
    run;
    [/pre]
  • Peter_C
    Rhodochrosite | Level 12
    as pointed out by data _null_, there is an option in SAS92. The topic is covered already at http://support.sas.com/forums/thread.jspa?threadID=8013 , pointing to Usage note on option INDSNAME= {VARname} see http://support.sas.com/kb/34/513.html . I managed this back in 2001, before INdsname= was available, with the techniques referred by earlier posters. My solution can be found on SAS-L at
    http://listserv.uga.edu/cgi-bin/wa?A2=ind0111A&L=sas-l&P=22975

    Message was edited by: Peter.C to refer to sas-L, 2001 fixing broken link 21/2/10. Message was edited by: Peter.C

    sas-innovate-2024.png

    Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

    Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

     

    Register now!

    What is Bayesian Analysis?

    Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

    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
    • 6 replies
    • 898 views
    • 0 likes
    • 5 in conversation