10-22-2015 08:04 PM
I'm running a query in where one set of data has a list of zip codes for members, and I have another file which has a list of zip codes and their corresponding region. The second file is used to map the regions for each zip code. However the first file has some zip codes that do not have a region for, thus when I run the query, I get the '.' value indicating this.
I would like to tell the query that when a match isn't there, instead of giving me '.' , I would rather it fill in the cell with 'NA' instead. I have tried using is null and is missing, but I keep getting a query error, stating that the 'when' statement does not match the requirements.
I am using SAS EG 7.1 and OS Windows 7, thank you.
10-22-2015 08:48 PM
10-22-2015 08:51 PM
I noticed that you mentioned "Query". I am not familiar with EG 7 environment. However, in case of a SQL, I would recommend using COALESCE function that will exactly do what you need. There should be something similar available on EG 7 or may be the same function is available.... worth looking up...
If you like to see details with examples for COALESCE (), here you go:
Hope this helps... Good Luck...!!!
10-22-2015 08:53 PM
@kannand solution is easier .
And SAS, SAS SQL supports the coalesce function. Process is the same, create a computed column with
10-23-2015 12:19 PM
Thank you all for the responses, the Coalesce function did exactly what I needed but I have one other issue, which is what I think what was given me trouble. The variable is considered a number, thus if I try to change it to 'NA' I get an error saying it doesn't match, I'm assuming I have to change my variable into a string. How would I go about doing that, so that I can use the Coalesce to give out an NA value?
10-23-2015 12:56 PM
10-23-2015 01:42 PM
Or create a custom format to display missing numeric as NA (or other text);
. = 'NA';
And associate that format with the variable. You don't have to change a data type, if you do calculations on the variable it is still treated as missing, and you need not make another pass through the data at all.
10-23-2015 01:56 PM - edited 10-23-2015 01:59 PM
I've incorporated the format solution by ballardw in the same example I stated earlier. The format and SQL statement is what you would need to focus.
data have;infile datalines dlm='09'x;
input F_Date:yymmdd8. Analyst_Code;
. = 'NA';
select f_date,analyst_code format=Na. from have;
10-25-2015 05:33 AM
If using SAS EG and your data is in SAS then you could also create a format with your lookup data (zipcode, region). With EG you can do this in a "point and click" manner using "Tasks/Date/Create format from data set".
Define "N/A" for your "other" cases
Then either create a new variable using "put(zipcode,<format.>)" or simply apply your format directly to the zipcode.