Desktop productivity for business analysts and programmers

Handling missing character variables

Reply
N/A
Posts: 0

Handling missing character variables

How can we distinguish a " " (blank) value with a null (missing) value for a character variable. Suppose I have a field in my input file with a field that can accept blank as a valid value:

Comma Delimited
Name (length = 20), At 25 Salary, Flag, Date of Birth (DDMntYY format),
Joe Williams, 70000, ,17Apr80
David Coleman, 91000,Y,29Nov70
Terrin Larson, 65000,F,01Jan00
Mathew Richardson, 85000,,02May78

There are number of missing values in this file. The last record has a missing value for the field "Flag", but the first record has a " " (blank) and valid value for this field. How can one read this file and capture the missing value distinguished from " " value?

I tried the below code for handling the subsequent ",". But don`t know how to know that the first record has a valid " " value for flag and the last record does not.

data MyLib.EmployeesWithFlag;
infile EmpFile dlm=',' firstobs=3 MissOver DSD;
length name $ 20.;
input name salary flag $ DoB Date7.;
run;

Thanks in advance for your taking time on this question.
Ramin
Esteemed Advisor
Posts: 5,198

Re: Handling missing character variables

I see your point. But if you want to store your flag as a character value, SAS does NOT distinguish between blank an MISSING/NULL, it's the same. In this case, would you consider to store any other value for your valid blank data?

If so, consider to read your whole record into one long string, and then use SAS character functions to find out if there is a blank or not between your delimeters.

Regards,
Linus
Data never sleeps
N/A
Posts: 0

Re: Handling missing character variables

Hi Linus,
Thanks for your message. I think I understood your solution for strings manipluation, which is interesting.
Regards,
Ramin
N/A
Posts: 0

Re: Handling missing character variables

I do not know whether I understand your question or not, I think it is the case to distinguish the space in the name and missing value. So why not use : modifier
Ask a Question
Discussion stats
  • 3 replies
  • 109 views
  • 0 likes
  • 2 in conversation