BookmarkSubscribeRSS Feed
D7
Calcite | Level 5 D7
Calcite | Level 5

Hi, I'm using a case else statement to try to create a new variable (source_flag) to fill in for blank for the first_source variable, however it is not populating the new variable definition of 'unknown' when it runs.  Any help would be greately appreciated.

 

proc sql;
create table d02_buyer_source_recency as
select DISTINCT email_id,
/* first source */
first_source,
first_available_source,
CASE when (first_source = ' ' OR first_source = '.') then 'UNKNOWN'
ELSE first_source END as Source_Flag
from oralib.sum_email_list_vw ;
quit;

4 REPLIES 4
collinelliot
Barite | Level 11

It's not fully clear without seeing your data, but you could try:

 

CASE first_source WHEN '' THEN 'UNKNOWN'

                              WHEN '.' THEN 'UNKNOWN'

                              ELSE first_source

END AS Source_Flag

D7
Calcite | Level 5 D7
Calcite | Level 5

Hi, thank you for your recommendation, however when I ran the adjustment still gettting 'blank' variable instead of 'unknown' in the source_flag fields.

 

collinelliot
Barite | Level 11

I assume first_source is character. Are there embedded blanks? Maybe put strip(first_source) for the CASE statement?

Tom
Super User Tom
Super User

Make sure your character variable is really empty. It might just look empty, but really include non-printing characters like tabs, line feeds, carriage returns, form feeds, non-breaking spaces, nulls.  

 

Also it might look like it has just a period in it, but it really has a period that follows one or move spaces.

CASE when compress(first_source) in (' ','.')  then 'UNKNOWN'
     ELSE first_source 
END as Source_Flag

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
  • 4 replies
  • 1976 views
  • 0 likes
  • 3 in conversation