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

Hi,

 

In the first code, the two missing values are properly displayed, but not in the second. Why not?

 

Below is the raw data:

 

90 80 98
78 88
65 66 69
92 94 96
78    79

First code.

Libname Learn'/folders/myfolders/Learn' ;

Data Problem_21_4 ; 
	infile '/folders/myfolders/Learn/Scores_List.sas' truncover ;   /*or Missover*/
	input (Score1-Score3) (2. + 1) ; 
run ; 	
	
proc print data=Problem_21_4 noobs ; 
run ; 

First Code results:

 

Score1 	Score2 	Score3
90 	80 	98
78 	88 	.
65 	66 	69
92 	94 	96
78 	. 	79

Second Code

 

Libname Review'/folders/myfolders/Review' ;
Libname Learn'/folders/myfolders/Learn' ; 

data review.Prob21_4 ;
	infile '/folders/myfolders/Learn/Scores_List.sas' truncover ; 
	input @1 Score1 : 2.
		  @4 Score2 : 2.
		  @7 Score3 : 2. ;
run ; 

proc print data=review.Prob21_4 ; 
run ; 

Second Code Results

 

Obs 	Score1 	Score2 	Score3
1 	90 	80 	98
2 	78 	88 	.
3 	65 	66 	69
4 	92 	94 	96
5 	78 	79 	79

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

While @novinosrin has the right "fix" to the problem, I think your question isn't how to fix it.  It looks like the question is, "Why does this happen?"

 

Since removing the colon impacts the results, it must be having an impact on how SAS reads the data.  More specifically, the colon means, "Scan across the data from left to right.  Once you find something, apply the instructions (2. in this case)."

 

So on the 5th line of data, SAS begins at column 4 and starts looking for a value.  It doesn't find anything until it gets to column 7 where it finds "79" (in columns 7 and 8).  So column 7 is where the INPUT statement starts applying the instructions = 2. = read the next two characters to get a value for SCORE2.

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Get rid of the colon format modifier if you are using formatter input and NOT modified list input like this in your 2nd to work

 

data Prob21_4 ;
	infile cards truncover ; 
	input @1 Score1  2.
		  @4 Score2  2.
		  @7 Score3  2. ;
cards;
90 80 98
78 88
65 66 69
92 94 96
78    79
;
run ; 
Astounding
PROC Star

While @novinosrin has the right "fix" to the problem, I think your question isn't how to fix it.  It looks like the question is, "Why does this happen?"

 

Since removing the colon impacts the results, it must be having an impact on how SAS reads the data.  More specifically, the colon means, "Scan across the data from left to right.  Once you find something, apply the instructions (2. in this case)."

 

So on the 5th line of data, SAS begins at column 4 and starts looking for a value.  It doesn't find anything until it gets to column 7 where it finds "79" (in columns 7 and 8).  So column 7 is where the INPUT statement starts applying the instructions = 2. = read the next two characters to get a value for SCORE2.

ManitobaMoose
Quartz | Level 8

Thanks. That is  correct. I wanted to know why it didn't work. Now I better understand the colon in this context. Thanks.

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
  • 726 views
  • 0 likes
  • 3 in conversation