Suppose I have two datasets named ds1, ds2 that have each 4 columns (their structure is the same):
ds1:
col1 | col2 | col3 | col4
================
122 | aaa | a1a1 | b1b1
124 | a1a | a2 | b2bb
235 | aaa | e34 | r45
ds2:
col1 | col2 | col3 | col4
================
224 | baa | a2a1 | b1b2
124 | a1a | a2 | b2bb
547 | aaa | e54 | v45
I am trying to write some code that will create a dataset containing col1 and col2 and a new column that would contain the dataset name.
The condition would be col2='aaa'
And the new dataset would look like this:
col1 | col2 | name
=============
122 | aaa | ds1
235 | aaa | ds1
547 | aaa | ds2
I wouldn't want to hardcode the name of the datasets in the new query.
Any suggestion would be greatly apprecited.
Something like this?
data WANT;
set DS1 DS2 indsname=INDS;
where COL2='aaa';
NAME=INDS;
keep COL1 COL2 NAME;
run;
Something like this?
data WANT;
set DS1 DS2 indsname=INDS;
where COL2='aaa';
NAME=INDS;
keep COL1 COL2 NAME;
run;
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.
Ready to level-up your skills? Choose your own adventure.