Reputation: 11
I'm working with data from a survey that allowed study participants to type in numeric responses, rather than providing them with a drop-down menu for them to select a numeric responses. As a result, I have responses that include characters (e.g. "9-12" or "7?"). I would like to identify the observations that have characters in them.
Thanks in advance!
The code I have in mind is getting me stuck on the WHERE statement.
PROC PRINT DATA=library.survey; VAR record_id; WHERE var1 ...... RUN;
Is there something I can write that's essentially telling SAS to print the record IDs where var1 doesn't equal a numeric value?
Upvotes: 1
Views: 404
Reputation: 51566
Just print the non-missing values that INPUT() cannot convert to a number. If they might have stuck in leading blanks then use the LEFT() function to remove them. Also watch out for values that are too long to be valid numbers.
where not missing(var1)
and (lengthn(left(var1)) <= 32 and missing(input(left(var1),?32.)))
Or use the COMMA informat instead of the normal informat and values with commas and/or dollar signs will also be treated as numbers.
Upvotes: 1
Reputation: 1103
One way you can do this is by regular expressions using prxmatch
.
proc print data=survey;
where prxmatch("/\D/",compress(var1));
run;
This will match any non digit characters. We use compress around var1
to remove any whitespace.
Upvotes: 0