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

SAS beginner using SAS Studio interface. I have the following sample dataset, and I'm having difficulties with the last step of the code:

 

Obs     Color                            Default

1          Blue                              Other

2          Teal                               Other

3          Teal                               Other

4          Yellow                           Other

5          Orange                         Other

 

data work.adjcolor;

set library.color;

if Color="Blue" or Color="Teal" then Adj_color="Blue;

else adj_color=default

run;

 

Adj_color is a new column I've created. What I would like to do is say "if adj_color" is missing/empty, then input values from 'default' into 'adj_color'." (So Adj_color when completed would have obs 1-5 'blue, blue, other, other, other'.'

 

I realize this is likely very basic, but I haven't been able to figure this out. Any help would be much much appreciated! Thanks in advance! 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisBrooks
Ammonite | Level 13

Hi @bretthouston and welcome to the community.

 

I'm not sure I see the problem here as the code you've got works for empty strings too (I also think given your logic observation number 3 should have adj_color as "Blue" not "Other").

 

Here's the example data I used

 

data have;
	infile datalines dlm="," dsd missover truncover;
	length color $6 default $6;
	input color default;
datalines;
"Blue","Other"
"Teal","Other"
"Teal","Other"
"Yellow","Other"
"Orange","Other"
"","Other"
;
run;

data want;
	length adj_color $6;
	set have;
	if color="Blue" or color="Teal" then adj_color="Blue";
	else adj_color=default;
run;

If I've misunderstood what you want please let us know

View solution in original post

1 REPLY 1
ChrisBrooks
Ammonite | Level 13

Hi @bretthouston and welcome to the community.

 

I'm not sure I see the problem here as the code you've got works for empty strings too (I also think given your logic observation number 3 should have adj_color as "Blue" not "Other").

 

Here's the example data I used

 

data have;
	infile datalines dlm="," dsd missover truncover;
	length color $6 default $6;
	input color default;
datalines;
"Blue","Other"
"Teal","Other"
"Teal","Other"
"Yellow","Other"
"Orange","Other"
"","Other"
;
run;

data want;
	length adj_color $6;
	set have;
	if color="Blue" or color="Teal" then adj_color="Blue";
	else adj_color=default;
run;

If I've misunderstood what you want please let us know

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 2368 views
  • 0 likes
  • 2 in conversation