Amadeus cookies policy - you'll see this message only once.

Amadeus use cookies on this website. They help us to know a little bit about you and how you use our website, which improves the browsing experience and marketing - both for you and for others. They are stored locally on your computer or mobile device. To accept cookies, continue browsing as normal. Or, go to the privacy policy for more information.

The INDSNAME Option

The introduction of SAS 9.2 has seen a number of new data step options added that provide simple solutions to common programming problems. The INDSNAME option provides a convenient way of capturing the name of the SAS table which is contributing to the current observation being read into the data step. It works by saving the two level name of the data set into a variable of our choice.

Consider the example below which is reading in 2 lab data sets in sequence and appending the results into a single table. The INDSNAME option, as specified on the SET statement, identifies a new variable DSNAME which will store the name of the contributing data set.

This variable can then be used to populate a further variable, LAB_TYPE which identifies the type of lab data being read next to each observation. Note: the use of the SCAN and TRANSLATE functions to ensure we save the data set name and not the library reference in our new variable and we replace all underscores with blank spaces. The INDSNAME variable itself is not written out to the output table.

data haematology;
  length subjid $3 labtest $30 unit $15;
  input subjid visit labtest result unit;
  datalines;
001 7 Basophils 0.05 GI/L
001 7 Basophils(%) 0.2 %
run;

data clinical_chemistry; 
   length subjid $3 labtest $30 unit $15;
   input subjid visit labtest result unit;
   datalines;
001 7 Albumin 42 G/L
001 7 Bilirubin 12 UMOL/L
001 7 Creatinine 86 UMOL/L
run;
data labs; length lab_type $20; set haematology clinical_chemistry indsname=dsname; lab_type = translate(scan(dsname,2,'.'),' ','_'); run;