DATA Step, Macro, Functions and more

scan function

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

scan function

Hi,

My question is the code like,


data work.test;
title='A TALE OF TWO CITIES, CHARLES J. DICKENS'
WORD=SCAN(title,3,' ,');
run;

What is the value of word?
A. T
B. OF
C.DICKENS
D. ''MISSING CHARACTER VALUE

 

I have run this code in sas like,

 

data work1;
input title $ 1-39;
datalines;
A TALE OF TWO CITIES, CHARLES J. DICKENS
run;
data work1;
WORD=SCAN(title,3,' ,');
run;

 

And i got log message like,

 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
61
62 data work1;
63 input title $ 1-39;
64 datalines;
 
NOTE: The data set WORK.WORK1 has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
 
66 WORD=SCAN(title,3);
 
66 WORD=SCAN(title,3);
____
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
 
67 run;
68 data work1;
69 WORD=SCAN(title,3,' ,');
70 run;
 
NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).
69:11
NOTE: Variable title is uninitialized.
NOTE: The data set WORK.WORK1 has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
 
 
71
72 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
85

 

So,

What will be the answer comes? As my logic answer sholde be missing character value!

 

 


Accepted Solutions
Solution
‎03-18-2017 06:51 PM
PROC Star
Posts: 7,362

Re: scan function

You didn't include a set statement in your second datastep. e.g.

data work1;
input title $ 1-39;
datalines;
A TALE OF TWO CITIES, CHARLES J. DICKENS
run;

data work1;
  set work1;
WORD=SCAN(title,3,' ,');
run;

Art, CEO, AnalystFinder.com

View solution in original post


All Replies
Solution
‎03-18-2017 06:51 PM
PROC Star
Posts: 7,362

Re: scan function

You didn't include a set statement in your second datastep. e.g.

data work1;
input title $ 1-39;
datalines;
A TALE OF TWO CITIES, CHARLES J. DICKENS
run;

data work1;
  set work1;
WORD=SCAN(title,3,' ,');
run;

Art, CEO, AnalystFinder.com

Contributor
Posts: 43

Re: scan function

You must put ";" after every program line. Please
Put ";" sign after line below and try again :

title='A TALE OF TWO CITIES, CHARLES J. DICKENS';


Super User
Posts: 10,490

Re: scan function

If the "test" code doesn't include any external file references I would suggest that you start first by running the code as provided in the test.

 

For the question code as posted all of the answers are wrong unless you consider an empty dataset as "missing character value" as the code will not run at all. You are missng a ; at the end of line two.

New Contributor
Posts: 3

Re: scan function

 

data work1;

input title $ 1-55;

datalines;

A TALE OF TWO CITIES, CHARLES J. DICKENS

run;

 

data work1;

set work1;

WORD=SCAN(title,3,' ,');

run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 272 views
  • 1 like
  • 5 in conversation