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;

 

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