Determine whether a cell is populated or not then do something

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Determine whether a cell is populated or not then do something

[ Edited ]

I'm trying to find code that, in the PROC or DATA step, will create a new variable 1 for each row where the city variable contains data. I've found lots of examples on how to look for specifics within the data using IN or CONTAINS but I can't find an example of a code that looks to see, like a binary, if it is populated or not. I can create the new numeric variable easily enough, it's identifying the correct cells I am having issues with.

 

 

 

 


Accepted Solutions
Solution
‎01-31-2018 09:37 AM
PROC Star
Posts: 1,570

Re: Determine whether a cell is populated or not then do something

That's when you use boolean expressions. Simply take advantage of it-

data have;
set sashelp.class;
if _n_ in (1,3,5,7,9) then city='Chicago';
run;

data want;
set have;
missing_check=missing(city);
run;

View solution in original post


All Replies
Super User
Posts: 23,262

Re: Determine whether a cell is populated or not then do something

MISSING()?

Solution
‎01-31-2018 09:37 AM
PROC Star
Posts: 1,570

Re: Determine whether a cell is populated or not then do something

That's when you use boolean expressions. Simply take advantage of it-

data have;
set sashelp.class;
if _n_ in (1,3,5,7,9) then city='Chicago';
run;

data want;
set have;
missing_check=missing(city);
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 94 views
  • 0 likes
  • 3 in conversation