@FrustratedBio wrote:
I am attempting to run the code below in an attempt to recreate variables n1-n5 from the array. The problem is, it is not currenlty working and I can't figure out why.
Data STRING; Input STRING $10. X 1-2 Y 3 N1 6 N2 7 N3 8 N4 9 N5 10; State= Upcase (substr(STRING, 4,2)); Array N[5] $5 N1-N5; DO I= 1 to 5; N [I]= scan(String, I,.); end; Drop I; Datalines; 123nj76543 892NY10203 876pA83745 ;
One of the main problems you are having is that your read values into variables N1 through N5 as numeric values and then try to force use as character values, the $5 in the Array and Scan function.
Once a variable is created, and the input statement is implicitly creating everything except String as numeric, the type cannot change.
Is this what you expected:
Data STRING;
Input STRING $10.
X 1-2
Y 3
N1 6
N2 7
N3 8
N4 9
N5 10;
State= Upcase (substr(STRING, 4,2));
Datalines;
123nj76543
892NY10203
876pA83745
;
or maybe
Data STRING;
Input STRING $10.
X 1-2
Y 3
N1 $ 6
N2 $ 7
N3 $ 8
N4 $ 9
N5 $ 10;
State= Upcase (substr(STRING, 4,2));
Datalines;
123nj76543
892NY10203
876pA83745
;
or maybe
Data STRING;
Input STRING $10.
X 1-2
Y 3
N1 6
N2 7
N3 8
N4 9
N5 10;
State= Upcase (substr(STRING, 4,2));
Array Z[5] $5 Z1-Z5;
DO I= 1 to 5;
Z[I]= substr(String,i+5,1);
end;
Drop I;
Datalines;
123nj76543
892NY10203
876pA83745
;
Read you logs. Your first code shows these messages
258 Data STRING;
259 Input STRING $10.
260 X 1-2
261 Y 3
262 N1 6
263 N2 7
264 N3 8
265 N4 9
266 N5 10;
267 State= Upcase (substr(STRING, 4,2));
268 Array N[5] $5 N1-N5;
269 DO I= 1 to 5;
270 N [I]= scan(String, I,.);
271 end;
272 Drop I;
273 Datalines;
NOTE: Numeric values have been converted to character values at the places given by:
(Line):(Column).
270:23
NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
270:1
NOTE: Invalid numeric data, '123nj76543' , at line 270 column 8.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+--
274 123nj76543
STRING=123nj76543 X=12 Y=3 N1=. N2=. N3=. N4=. N5=. State=NJ I=6 _ERROR_=1 _N_=1
NOTE: Invalid numeric data, '892NY10203' , at line 270 column 8.
275 892NY10203
STRING=892NY10203 X=89 Y=2 N1=. N2=. N3=. N4=. N5=. State=NY I=6 _ERROR_=1 _N_=2
NOTE: Invalid numeric data, '876pA83745' , at line 270 column 8.
276 876pA83745
STRING=876pA83745 X=87 Y=6 N1=. N2=. N3=. N4=. N5=. State=PA I=6 _ERROR_=1 _N_=3
NOTE: The data set WORK.STRING has 3 observations and 9 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
The invalid data on line 270 is from the SCAN function. The dot in your scan is not a valid SCAN function third parameter. It has to hold a character value either as a variable or a quoted string such as ".". But there is no obvious delimiter or separator in the value of String so you need a different approach to get values out of it with character functions.
... View more