BookmarkSubscribeRSS Feed
EricB40
Fluorite | Level 6

Hi everyone,

 

My data is from a big csv file and in that file, the authors used ####### as a missing value. How do I get sas to identify this as a missing value and not try to fill it in?

My code right now is: 

proc import out=work.problems
datafile="/home/u63556826/sasuser.v94/problems.csv"
dbms=csv
replace;
getnames=YES;
run;

proc print data=work.problems (obs = 6); run;

 

 

6 REPLIES 6
Quentin
Super User

While there are ways to do this when you read in the data, it will probably be easier to convert it after you have read the data into a SAS dataset.

 

So you could do:

data problems2;
  set problems ;
  array chars{*} _character_ ;
  do i=1 to dim(chars);
    if chars{i}='########' then call missing(chars{i});
  end;
run;

And if you want numeric variables, you could add code to create numeric variables from the character variables, using the INPUT function.

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
EricB40
Fluorite | Level 6

Would that look something like this:

 

proc import out=work.problems
datafile="/home/u63556826/sasuser.v94/problems.csv"
dbms=csv
replace;
getnames=YES;
run;

data problems2;
set problems ;
array chars{*} _character_ ;
do i=1 to dim(chars);
if chars{i}='########' then call missing(chars{i});
end;
run;

proc print data=work.problems (obs = 6); run;

Quentin
Super User

Yes, that was my thought.  How does it work for your need?

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
mkeintz
PROC Star

If the data are in a text or csv or other ascii file, you can use INFORMATs to tell SAS to convert '########' to missing values, both for numeric, and for character variables:

 

proc format ;
  invalue shnum '########'=.
           other=[best32.];
  invalue $shchr '########'=' '  min=8 max=20
           other=[$20.];
run;

data test;
  informat default=shnum. ;
  input id $5.  num1  num2  char1 :$shchr10. char2 :$shchr. ;
datalines;
AAAAA ######## 1002     ch11_6789A ch12_6789ABC
BBBBB 2001     2002     ########   ch22_6789ABC
CCCCC 3001     ######## ch31_6789A ########
DDDDD ######## ######## ########   ########
run;
proc print;
  var id num1 num2 char1 char2;
run;

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
andreas_lds
Jade | Level 19

Importing a csv file with non-standard missing values (standard = empty field) with proc import will lead to extra work and may lead to variables with a wrong guessed type. So better write a data step yourself to avoid all the things you have to do get the data step with proper typed variables (and lengths).

ballardw
Super User

@andreas_lds wrote:

Importing a csv file with non-standard missing values (standard = empty field) with proc import will lead to extra work and may lead to variables with a wrong guessed type. So better write a data step yourself to avoid all the things you have to do get the data step with proper typed variables (and lengths).


Definitely agree. I have data sources where they can't even be consistent and one file will have: NA, not answered, UNK , unknown, refused to answer in ONE variable just for what should be missing values. Proc format can handle multiple strings like that to all set one standard "missing" value.

 

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1129 views
  • 4 likes
  • 5 in conversation