turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Possible to conditionally add variable based on ob...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-18-2016 03:32 AM

Hi there,

I havn't been able to google/find this issue, therefore this post.

```
data want;
set have1 have2 have3;
length Source $5;
```

where something = &a_variable.;

if [observations are from have1] then Source="have1";
if [observations are from have2] then Source="have2";
if [observations are from have3] then Source="have3";
run;

Is something like this possible? In the log it always shows how many observations SAS is able to find from the different datasets put in the set statement.

NOTE: There were 27834 observations read from the data set WORK.HAVE1.

NOTE: There were 0 observations read from the data set WORK.HAVE2.

NOTE: There were 22808 observations read from the data set WORK.HAVE3.

Is it also possible to conditionally do something based on those observations? Like add a variable with the source of the obs? I am running SAS 9.4.

Accepted Solutions

Solution

08-18-2016
03:54 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Kristiaan

08-18-2016 03:35 AM

INDSNAME option on the SET statement.

See example 12 in the documentation, which is exactly your question.

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Kristiaan

08-18-2016 03:35 AM

```
data want;
set
have1 (in=have1)
have2 (in=have2)
have3 (in=have3)
;
length Source $5;
where something = &a_variable.;
if have1 then Source="have1";
if have2 then Source="have2";
if have3 then Source="have3";
run;
```

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers

Solution

08-18-2016
03:54 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Kristiaan

08-18-2016 03:35 AM

INDSNAME option on the SET statement.

See example 12 in the documentation, which is exactly your question.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

08-18-2016 03:53 AM

Both options work perfectly, thanks for the quick reply!