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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Something like this?

data WANT;
  set DS1 DS2 indsname=INDS;
  where COL2='aaa';
  NAME=INDS;
  keep COL1 COL2 NAME;
run;

 

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Something like this?

data WANT;
  set DS1 DS2 indsname=INDS;
  where COL2='aaa';
  NAME=INDS;
  keep COL1 COL2 NAME;
run;

 

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
  • 2 replies
  • 942 views
  • 1 like
  • 2 in conversation