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

I want to exclude records where the question_caption is "indicate relationship" because the score_value is NULL. When I use the infile statement as is below, I get a warning that there is invalid data for  score_value for those records.

 

data outcome;
infile 'filepath\formname.csv' dlm=',' dsd firstobs=1 lrecl=1000;
input 
id :$50.
event_name :$50.
test_header_name :$50.
question_caption :$75.
score_value 
answer_value :$50.;
run;

Currently I am just using a data step (below) after that to exclude those records. But I would preference not bringing them in at all.

data outcome_b;
	set outcome;
	where question_caption notin ("Indicate relationship");
run;

Is there a way in my infile statement to exclude these records?

 

Thanks in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

No. you cannot use the INFILE statement to filter the data.  But you can tell the data step with the INFILE statement to filter the data after you have read it (so you have something to test!).

data outcome;
  infile 'filepath\formname.csv' dlm=',' dsd firstobs=1 lrecl=1000;
  input 
    id :$50.
    event_name :$50.
    test_header_name :$50.
    question_caption :$75.
    score_value 
    answer_value :$50.
  ;
  if question_caption not in ("Indicate relationship");
run;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

No. you cannot use the INFILE statement to filter the data.  But you can tell the data step with the INFILE statement to filter the data after you have read it (so you have something to test!).

data outcome;
  infile 'filepath\formname.csv' dlm=',' dsd firstobs=1 lrecl=1000;
  input 
    id :$50.
    event_name :$50.
    test_header_name :$50.
    question_caption :$75.
    score_value 
    answer_value :$50.
  ;
  if question_caption not in ("Indicate relationship");
run;
ddavies
Calcite | Level 5

Thanks for the quick answer, I was hoping to not get the warning at all but this works and saves a step. Thank you!

Tom
Super User Tom
Super User

@ddavies wrote:

Thanks for the quick answer, I was hoping to not get the warning at all but this works and saves a step. Thank you!


Are you saying the CSV file you are reading someone typed the letters NULL when the value of SCORE was missing?

You can use format modifiers to suppress ALL error messages when reading SCORE.

input ... score ??  ... ;

Or create a custom informat that maps the string NULL to whatever value you want.  You could map it missing or a special missing for example.

proc format;
invalue null 'NULL'=.N ;
run;
....
input ... score :null32. ...

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 3 replies
  • 1118 views
  • 0 likes
  • 2 in conversation