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
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.
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 ;
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.
Thanks. That is correct. I wanted to know why it didn't work. Now I better understand the colon in this context. Thanks.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.