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

 hi experts,

 

the dataset i have

column1

-

2.5

30.59

H 200

87 mg/dL

90 L

28.3

 

the dataset that i want

column1

 

2.5

30.59

 

 

 

28.3

 

if my column contain any variable, i want to set that as missing

 

TIA

 

1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12
data have;
  length var $20;
  infile datalines dlm=',';
  input var $;
datalines;
-
2.5
30.59
H 200
87 mg/dL
90 L
28.3
;
run;

data want;
  set have;
  var=ifc(input(var,??best.)=.,'',var);
run;

View solution in original post

4 REPLIES 4
japelin
Rhodochrosite | Level 12
data have;
  length var $20;
  infile datalines dlm=',';
  input var $;
datalines;
-
2.5
30.59
H 200
87 mg/dL
90 L
28.3
;
run;

data want;
  set have;
  var=ifc(input(var,??best.)=.,'',var);
run;
Pooja98
Fluorite | Level 6

Thanks a lot... i got the answer but i still have doubt in this

 

"var=ifc(input(var,??best.)=.,'',var);"

 

What it mean: input(var, ??best.)= .

The input function converts character to numeric then what is that "=."........

can you please explain that

Tom
Super User Tom
Super User

@Pooja98 wrote:

Thanks a lot... i got the answer but i still have doubt in this

 

"var=ifc(input(var,??best.)=.,'',var);"

 

What it mean: input(var, ??best.)= .

The input function converts character to numeric then what is that "=."........

can you please explain that


Since your variable is character this code is using the INPUT() function to check it the value can be converted into a number.  When it can it sets the the variable back to itself otherwise it sets it to blanks.

The ?? before the informat will suppress any error messages about strings that cannot be converted into a number.

 

You can make it less confusing by just using an IF/THEN statement instead of the confusing IFC() function.

You can make the test less confusing also by not trying to use the name of a FORMAT in the place where SAS is expecting the name of an INFORMAT.  If you reference BEST as an INFORMAT it is just an alias for the normal numeric informat.

You can also use the MISSING() function instead of just comparing the INPUT() result to the numeric missing value.  In addition to being more readable for humans this will also catch the issue where value like E being converted to special missing .E which is not equal to . but will be considered missing by the MISSING() function.

 

if missing(input(var,??32.)) then var=' ';

Note also that if you wanted to create an actual numeric variable you will have to give that variable a new name.  You cannot change the type of an existing variable.  In that case the code is even easier (clearer).  

 

So if have an existing dataset named HAVE with a character variable named STR and you want to create a new variable name NUM that is numeric then use:

data want;
  set have;
  num = input(str,??32.);
run;

If you would like to see messages in the log when the value of STR could not be converted to a number then remove the ?? from before the informat.

japelin
Rhodochrosite | Level 12

Thank you for your explanation, @Tom .
I also noticed after posting that ifc would cause unnecessary processing, so I think a simple if then statement would be better.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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