Help using Base SAS procedures

How to check if a var is null within Proc SQL

Reply
Super Contributor
Posts: 398

How to check if a var is null within Proc SQL

I have a proc sql statement that I'm trying to check if a variable is null or not.

proc sql ;

create table x

as

select id, case when Search = 'Yahoo' then '<a href="www.yahoo.com">Yahoo</a>' || ' ' ||    ??????

quit ;

At this point I want to replace ?????? with a way to check my variable to see if there is data or not.  If there is I want to add more text if not then continue to the next step.

I want to add brackets around my value if it isn't null.

Ex. The variable has data :  Yahoo  [Bob]

Ex. The variable no data :  Yahoo

Thanks

Super User
Posts: 10,531

Re: How to check if a var is null within Proc SQL

when missing(variablename) then ...

would be the general approach

Super Contributor
Posts: 398

Re: How to check if a var is null within Proc SQL

Ballardw,

Thanks for the reply.  Would that when belong to another case statement?

Within this contatnation i'm doing there will be multiple variables that could be null and if they are I don't want the text that identifies them to display.  I want it to display only if there is data.

Thanks

Super User
Posts: 10,531

Re: How to check if a var is null within Proc SQL

Another case statement at this point. I'm not sure how many levels of nesting SAS SQL will handle. It may be worth looking into a datastep at least for manipulating the individual variables to have the [] or whatnot done to them and then an appropriate CATX CATS or whichever to concatenate them into one variable to insert in to the final string.

Super Contributor
Posts: 398

Re: How to check if a var is null within Proc SQL

Ballardw,

Thank you so much.  I'm going to start out the morning trying to use a data step.  I think with an if statement and catx or cats I can get it working that way.

I will reply my results.

Thanks

Ask a Question
Discussion stats
  • 4 replies
  • 1670 views
  • 3 likes
  • 2 in conversation