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

Hi all,

 

I'm new here, as well as I'm quite new on SAS Enterprise Guide. I have a question about what I think should be an IF/THEN-statement, but since I'm still a noob, I don't know how to perform this statement correctly.

 

I have a column (let's call it COLUMNONE) with thousands of codes and a second column with codes (COLUMNTWO). What I would like to see is that if COLUMNONE contains a certain value, then that value should be replaced with the value stated in COLUMNTWO. If COLUMNONE does not contain that specific value (but something else), then nothing should happen.

 

Example.

COLUMNONE contains codes like 5.19.XXXXXXX or 6.07.XXXXXXX, where X are random numbers. Now, if COLUMNONE has a code that starts with '5.19.' (what comes on the Xs is not relevant), then I want the code that is stated in COLUMNTWO. If COLUMNONE has a code other then starting with '5.19.' it's fine and no changes are needed.

 

Can anyone please provide the steps I need to take in order to perform this?? If you need any more information please ask!

 

Cheers 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

Try to add an advanced expression in the Expression editor  like this:

 

case 
 when substr(t1.columnone,1,4)= '5,19' then t1.columntwo
 else t1.columnone
end

The query builder will add the "AS newcolumnname" at the end to create your new calculated column

Become an Explorer! Join SAS Analytics Explorers to learn and complete challenges that earn rewards!

View solution in original post

4 REPLIES 4
LinusH
Tourmaline | Level 20

If get you logic correctly:


If you are using the query builder in EG, you need to think SQL case-when-then-else instead. For this, there is a kind of point-and-click interface.

 

Using progamming with the data step (untested):

 

 

data want;
    set have;
    if substr(columnone,1,4) = '5,19' then columnone = cats(substr(columntwo,1,4),substr(columnsone,5));
run;

 

Data never sleeps
jenzie44
Fluorite | Level 6

Thanks for the quick reply.

 

Is it also possible to build this through the computed column editor (advanced expression)?

ChrisHemedinger
Community Manager

Try to add an advanced expression in the Expression editor  like this:

 

case 
 when substr(t1.columnone,1,4)= '5,19' then t1.columntwo
 else t1.columnone
end

The query builder will add the "AS newcolumnname" at the end to create your new calculated column

Become an Explorer! Join SAS Analytics Explorers to learn and complete challenges that earn rewards!
jenzie44
Fluorite | Level 6

Great. Thanks. It works!

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 4 replies
  • 3270 views
  • 1 like
  • 3 in conversation