BookmarkSubscribeRSS Feed
MarcTC
Obsidian | Level 7
I wonder if there is a better way to create a indicator variable as shown in the following sql statement:

proc sql;
create table ds3 as
select a.*,
case
when b.id = '' then 0
else 1
end as ind
from ds1 a left join ds2 b
on a.id = b.id
; quit;
2 REPLIES 2
Ksharp
Super User
I think your code is good enough.If you want more brief.
[pre]
data class;
set sashelp.class end=last; output;
if last then do;
name='Peter';sex=' '; output;
end;

proc sql;
create table temp as
select a.*,not missing(a.sex) as ind
from class as a left join class as b on a.sex=b.sex;
quit;
[/pre]


Ksharp
SASJedi
SAS Super FREQ
You can make your code a touch more efficient with a little boolean logic:

proc sql;
create table ds3 as
select a.*
, b.id NE '' as ind
from ds1 a left join ds2 b
on a.id = b.id
;
quit;

Message was edited by: SASJedi Message was edited by: SASJedi
Check out my Jedi SAS Tricks for SAS Users

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 10038 views
  • 2 likes
  • 3 in conversation