BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Godzilla_Hat
Obsidian | Level 7
data dmv;
input 
	ID      3-5 @    
	Score   13-14 @
	Age    6-7 @
	Code   8-12 @
	State 1-2 @;

datalines;
AR373535867443
CO884198099142
CO844117922301
CT892260212694
GA544146397264
FL116356242135
FL012766334163
IA284575080076
MO201819486741
MN333660025825
NC521620806587
NC391625607716
NY242148623172
OH498277408248
TX334618334735

;
run;

TITLE "input data";
PROC PRINT DATA=dmv;
RUN;

error .png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Note that State is a string, and ID and Code should probably also be handled as character, so use this:

data dmv;
input 
  @3 ID $3.
  @13 Score 2.
  @6 Age 2.
  @8 Code $5.
  @1 State $2.
;
datalines;
AR373535867443
CO884198099142
CO844117922301
CT892260212694
GA544146397264
FL116356242135
FL012766334163
IA284575080076
MO201819486741
MN333660025825
NC521620806587
NC391625607716
NY242148623172
OH498277408248
TX334618334735
;

 

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

What do you thing those @ in the INPUT statement are for?
To SAS it looks like you started with:

input id 3-5  @SCORE ....

So the @ score means move to the column number of the value of SCORE.  Just like @ 10 means move to column 10.

So it is expecting the name of the variable you want to read from columns 13 to 14 to appear between the variable that the @ pointer motion is using and the 13.

 

Remove the @ 's .

  input 
    ID      3- 5    
    Score  13-14 
    Age     6- 7 
    Code    8-12 
    State   1- 2 
  ;

Note it is probably easier if you have some reason for wanting ID to be the first variable instead of the second to just tell SAS that directly and then have the INPUT statement read the variables in the order they actually appear on the line.

data dmv;
  length ID Score Age Code State 8;
  input 
    State   1- 2 
    ID      3- 5    
    Age     6- 7 
    Code    8-12 
    Score  13-14 
  ;

Or

data dmv;
  length ID Score Age Code State 8;
  input 
    State   2.
    ID      3.
    Age     2.
    Code    5.
    Score   2.
  ;

 

 

Kurt_Bremser
Super User

Note that State is a string, and ID and Code should probably also be handled as character, so use this:

data dmv;
input 
  @3 ID $3.
  @13 Score 2.
  @6 Age 2.
  @8 Code $5.
  @1 State $2.
;
datalines;
AR373535867443
CO884198099142
CO844117922301
CT892260212694
GA544146397264
FL116356242135
FL012766334163
IA284575080076
MO201819486741
MN333660025825
NC521620806587
NC391625607716
NY242148623172
OH498277408248
TX334618334735
;

 

Ksharp
Super User

"STAT" is character variable ,therefore you need $ to define it .

 

data dmv;
input ID      3-5  
	Score   13-14
	Age    6-7
	Code   8-12
	State  $ 1-2 ;

datalines;
AR373535867443
CO884198099142
CO844117922301
CT892260212694
GA544146397264
FL116356242135
FL012766334163
IA284575080076
MO201819486741
MN333660025825
NC521620806587
NC391625607716
NY242148623172
OH498277408248
TX334618334735
;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 450 views
  • 0 likes
  • 4 in conversation